Skip to content

Commit

Permalink
PR comments - styling and test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexparlett committed Mar 26, 2021
1 parent 50735e5 commit cd6ddea
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
52 changes: 26 additions & 26 deletions src/vault/authenticate.clj
Expand Up @@ -14,10 +14,10 @@
(let [auth-info (lease/auth-lease (:auth (api-util/clean-body response)))]
(when-not (:client-token auth-info)
(throw (ex-info (str "No client token returned from non-error API response: "
(:status response) " " (:reason-phrase response))
{:body (:body response)})))
(:status response) " " (:reason-phrase response))
{:body (:body response)})))
(log/info "Successfully authenticated to Vault as %s for policies: %s"
claim (str/join ", " (:policies auth-info)))
claim (str/join ", " (:policies auth-info)))
(reset! auth-ref auth-info)))


Expand All @@ -31,7 +31,7 @@
(defmethod authenticate* :default
[_ auth-type _]
(throw (ex-info (str "Unsupported auth-type " (pr-str auth-type))
{:auth-type auth-type})))
{:auth-type auth-type})))


(defmethod authenticate* :token
Expand Down Expand Up @@ -59,10 +59,10 @@
:post (str (:api-url client) "/v1/auth/userpass/" (:auth-mount-point client) "login/" username)
(merge
(:http-opts client)
{:form-params {:password password}
{:form-params {:password password}
:content-type :json
:accept :json
:as :json})))))
:accept :json
:as :json})))))


(defmethod authenticate* :app-id
Expand All @@ -75,10 +75,10 @@
:post (str (:api-url client) "/v1/auth/app-id/" (:auth-mount-point client) "login")
(merge
(:http-opts client)
{:form-params {:app_id app, :user_id user}
{:form-params {:app_id app, :user_id user}
:content-type :json
:accept :json
:as :json})))))
:accept :json
:as :json})))))


(defmethod authenticate* :app-role
Expand All @@ -91,10 +91,10 @@
:post (str (:api-url client) "/v1/auth/approle/" (:auth-mount-point client) "login")
(merge
(:http-opts client)
{:form-params {:role_id role-id, :secret_id secret-id}
{:form-params {:role_id role-id, :secret_id secret-id}
:content-type :json
:accept :json
:as :json})))))
:accept :json
:as :json})))))


(defmethod authenticate* :ldap
Expand All @@ -107,10 +107,10 @@
:post (str (:api-url client) "/v1/auth/ldap/" (:auth-mount-point client) "login/" username)
(merge
(:http-opts client)
{:form-params {:password password}
{:form-params {:password password}
:content-type :json
:accept :json
:as :json})))))
:accept :json
:as :json})))))


(defmethod authenticate* :k8s
Expand All @@ -128,10 +128,10 @@
:post (str (:api-url client) api-path)
(merge
(:http-opts client)
{:form-params {:jwt jwt :role role}
{:form-params {:jwt jwt :role role}
:content-type :json
:accept :json
:as :json})))))
:accept :json
:as :json})))))


(defmethod authenticate* :aws-iam
Expand All @@ -156,11 +156,11 @@
:post (str (:api-url client) api-path)
(merge
(:http-opts client)
{:form-params {:iam_http_request_method http-request-method
:iam_request_url request-url
:iam_request_body request-body
:iam_request_headers request-headers
:role role}
{:form-params {:iam_http_request_method http-request-method
:iam_request_url request-url
:iam_request_body request-body
:iam_request_headers request-headers
:role role}
:content-type :json
:accept :json
:as :json})))))
:accept :json
:as :json})))))
48 changes: 24 additions & 24 deletions test/vault/client/http_test.clj
Expand Up @@ -104,10 +104,10 @@
(swap! api-auths conj args)
:api-auth!-response)]
(vault/authenticate! client :aws-iam {:role "my-role"
:iam-http-request-method "POST"
:iam-request-url "fake.sts.com"
:iam-request-body "FakeAction&Version=1"
:iam-request-headers "{'foo':'bar'}"})
:http-request-method "POST"
:request-url "fake.sts.com"
:request-body "FakeAction&Version=1"
:request-headers "{'foo':'bar'}"})
(is (= [[:post
(str example-url "/v1/auth/aws/login")
{:form-params {:iam_http_request_method "POST"
Expand All @@ -123,7 +123,7 @@
(:auth client)
:do-api-request-response]]
@api-auths)))))
(testing "When no iam-http-request-method is specified"
(testing "When no http-request-method is specified"
(let [client (http-client example-url)
api-requests (atom [])
api-auths (atom [])]
Expand All @@ -133,12 +133,12 @@
(swap! api-auths conj args))]
(is (thrown? IllegalArgumentException
(vault/authenticate! client :aws-iam {:role "my-role"
:iam-request-url "fake.sts.com"
:iam-request-body "FakeAction&Version=1"
:iam-request-headers "{'foo':'bar'}"})))
:request-url "fake.sts.com"
:request-body "FakeAction&Version=1"
:request-headers "{'foo':'bar'}"})))
(is (empty? @api-requests))
(is (empty? @api-auths)))))
(testing "When no iam-request-url is specified"
(testing "When no request-url is specified"
(let [client (http-client example-url)
api-requests (atom [])
api-auths (atom [])]
Expand All @@ -148,12 +148,12 @@
(swap! api-auths conj args))]
(is (thrown? IllegalArgumentException
(vault/authenticate! client :aws-iam {:role "my-role"
:iam-http-request-method "POST"
:iam-request-body "FakeAction&Version=1"
:iam-request-headers "{'foo':'bar'}"})))
:http-request-method "POST"
:request-body "FakeAction&Version=1"
:request-headers "{'foo':'bar'}"})))
(is (empty? @api-requests))
(is (empty? @api-auths)))))
(testing "When no iam-request-body is specified"
(testing "When no request-body is specified"
(let [client (http-client example-url)
api-requests (atom [])
api-auths (atom [])]
Expand All @@ -163,12 +163,12 @@
(swap! api-auths conj args))]
(is (thrown? IllegalArgumentException
(vault/authenticate! client :aws-iam {:role "my-role"
:iam-http-request-method "POST"
:iam-request-url "fake.sts.com"
:iam-request-headers "{'foo':'bar'}"})))
:http-request-method "POST"
:request-url "fake.sts.com"
:request-headers "{'foo':'bar'}"})))
(is (empty? @api-requests))
(is (empty? @api-auths)))))
(testing "When no iam-request-headers is specified"
(testing "When no request-headers is specified"
(let [client (http-client example-url)
api-requests (atom [])
api-auths (atom [])]
Expand All @@ -178,9 +178,9 @@
(swap! api-auths conj args))]
(is (thrown? IllegalArgumentException
(vault/authenticate! client :aws-iam {:role "my-role"
:iam-http-request-method "POST"
:iam-request-url "fake.sts.com"
:iam-request-body "FakeAction&Version=1"})))
:http-request-method "POST"
:request-url "fake.sts.com"
:request-body "FakeAction&Version=1"})))
(is (empty? @api-requests))
(is (empty? @api-auths)))))
(testing "When no role is specified"
Expand All @@ -192,9 +192,9 @@
authenticate/api-auth! (fn [& args]
(swap! api-auths conj args))]
(is (thrown? IllegalArgumentException
(vault/authenticate! client :aws-iam {:iam-http-request-method "POST"
:iam-request-url "fake.sts.com"
:iam-request-body "FakeAction&Version=1"
:iam-request-headers "{'foo':'bar'}"})))
(vault/authenticate! client :aws-iam {:http-request-method "POST"
:request-url "fake.sts.com"
:request-body "FakeAction&Version=1"
:request-headers "{'foo':'bar'}"})))
(is (empty? @api-requests))
(is (empty? @api-auths))))))

0 comments on commit cd6ddea

Please sign in to comment.