Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: server/auth/delegation/minter_test.go

Issue 2386643003: auth: Make luci-go services trust signatures produced by the token server. (Closed)
Patch Set: add tests Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « server/auth/delegation/checker_test.go ('k') | server/auth/internal/fetch.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/auth/delegation/minter_test.go
diff --git a/server/auth/delegation/minter_test.go b/server/auth/delegation/minter_test.go
index 07f49ff0744477545a10f0459d0231c3605b11cd..3632a6f80b06540d3b9457399c92270f1b5be3b5 100644
--- a/server/auth/delegation/minter_test.go
+++ b/server/auth/delegation/minter_test.go
@@ -5,8 +5,6 @@
package delegation
import (
- "bytes"
- "io/ioutil"
"net/http"
"testing"
"time"
@@ -36,11 +34,15 @@ func TestCreateToken(t *testing.T) {
Intent: "intent",
}
- ctx, tr := withTestTransport(ctx, `{
- "delegation_token": "tok",
- "validity_duration": 3600,
- "subtoken_id": "123"
- }`)
+ lastRequestBody := ""
+ ctx = internal.WithTestTransport(ctx, func(r *http.Request, body string) (int, string) {
+ lastRequestBody = body
+ return 200, `{
+ "delegation_token": "tok",
+ "validity_duration": 3600,
+ "subtoken_id": "123"
+ }`
+ })
Convey("Works", t, func() {
tok, err := CreateToken(ctx, goodReq)
@@ -50,7 +52,7 @@ func TestCreateToken(t *testing.T) {
SubtokenID: "123",
Expiry: testclock.TestRecentTimeUTC.Add(time.Hour),
})
- So(tr.request, ShouldEqual,
+ So(lastRequestBody, ShouldEqual,
`{"audience":["user:a@example.com","group:group"],`+
`"services":["service:abc"],"validity_duration":3600,`+
`"impersonate":"user:b@example.com","intent":"intent"}`)
@@ -94,35 +96,3 @@ func TestCreateToken(t *testing.T) {
So(err, ShouldBeNil)
})
}
-
-var testTransportKey = "key for testTransport"
-
-func withTestTransport(c context.Context, response string) (context.Context, *testTransport) {
- t := &testTransport{response: response}
- return context.WithValue(c, &testTransportKey, t), t
-}
-
-type testTransport struct {
- response string
- request string
-}
-
-func (f *testTransport) RoundTrip(r *http.Request) (*http.Response, error) {
- body, err := ioutil.ReadAll(r.Body)
- r.Body.Close()
- if err != nil {
- return nil, err
- }
- f.request = string(body)
- return &http.Response{
- StatusCode: 200,
- Status: "OK",
- Body: ioutil.NopCloser(bytes.NewReader([]byte(f.response))),
- }, nil
-}
-
-func init() {
- internal.RegisterClientFactory(func(c context.Context, scopes []string) (*http.Client, error) {
- return &http.Client{Transport: c.Value(&testTransportKey).(*testTransport)}, nil
- })
-}
« no previous file with comments | « server/auth/delegation/checker_test.go ('k') | server/auth/internal/fetch.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698