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

Side by Side Diff: server/auth/internal/testing.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 unified diff | Download patch
« no previous file with comments | « server/auth/internal/fetch.go ('k') | server/auth/signing/signingtest/signer.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package internal
6
7 import (
8 "bytes"
9 "io/ioutil"
10 "net/http"
11 "sync"
12
13 "golang.org/x/net/context"
14 )
15
16 var testTransportKey = "testTransport"
17
18 // TestTransportCallback is used from unit tests.
19 type TestTransportCallback func(r *http.Request, body string) (code int, respons e string)
20
21 // WithTestTransport puts a testing transport in the context to use for fetches.
22 func WithTestTransport(c context.Context, cb TestTransportCallback) context.Cont ext {
23 return context.WithValue(c, &testTransportKey, &testTransport{cb: cb})
24 }
25
26 type testTransport struct {
27 lock sync.Mutex
28 cb TestTransportCallback
29 }
30
31 func (t *testTransport) RoundTrip(r *http.Request) (*http.Response, error) {
32 t.lock.Lock()
33 defer t.lock.Unlock()
34 body, err := ioutil.ReadAll(r.Body)
35 r.Body.Close()
36 if err != nil {
37 return nil, err
38 }
39 code, resp := t.cb(r, string(body))
40 return &http.Response{
41 StatusCode: code,
42 Body: ioutil.NopCloser(bytes.NewReader([]byte(resp))),
43 }, nil
44 }
OLDNEW
« no previous file with comments | « server/auth/internal/fetch.go ('k') | server/auth/signing/signingtest/signer.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698