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

Side by Side Diff: server/auth/authtest/state.go

Issue 2830443003: auth: Refactor how authentication methods are passed to server/auth library. (Closed)
Patch Set: fix test Created 3 years, 8 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/authtest/method.go ('k') | server/auth/context.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package authtest 5 package authtest
6 6
7 import ( 7 import (
8 "net" 8 "net"
9 9
10 "github.com/luci/luci-go/server/auth" 10 "github.com/luci/luci-go/server/auth"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 PeerIdentityOverride identity.Identity 45 PeerIdentityOverride identity.Identity
46 46
47 // PeerIPOverride may be set for PeerIP() to return custom value. 47 // PeerIPOverride may be set for PeerIP() to return custom value.
48 // 48 //
49 // By default PeerIP() returns "127.0.0.1". 49 // By default PeerIP() returns "127.0.0.1".
50 PeerIPOverride net.IP 50 PeerIPOverride net.IP
51 } 51 }
52 52
53 var _ auth.State = (*FakeState)(nil) 53 var _ auth.State = (*FakeState)(nil)
54 54
55 // Authenticator is part of State interface.
56 func (s *FakeState) Authenticator() *auth.Authenticator {
57 return &auth.Authenticator{
58 Methods: []auth.Method{
59 &FakeAuth{User: s.User()},
60 },
61 }
62 }
63
55 // DB is part of State interface. 64 // DB is part of State interface.
56 func (s *FakeState) DB() authdb.DB { 65 func (s *FakeState) DB() authdb.DB {
57 if s.FakeDB != nil { 66 if s.FakeDB != nil {
58 return s.FakeDB 67 return s.FakeDB
59 } 68 }
60 return &FakeErroringDB{ 69 return &FakeErroringDB{
61 FakeDB: FakeDB{s.User().Identity: s.IdentityGroups}, 70 FakeDB: FakeDB{s.User().Identity: s.IdentityGroups},
62 Error: s.Error, 71 Error: s.Error,
63 } 72 }
64 } 73 }
65 74
66 // Method is part of State interface. 75 // Method is part of State interface.
67 func (s *FakeState) Method() auth.Method { 76 func (s *FakeState) Method() auth.Method {
68 » return &FakeAuth{ 77 » return s.Authenticator().Methods[0]
69 » » User: s.User(),
70 » }
71 } 78 }
72 79
73 // User is part of State interface. 80 // User is part of State interface.
74 func (s *FakeState) User() *auth.User { 81 func (s *FakeState) User() *auth.User {
75 ident := identity.AnonymousIdentity 82 ident := identity.AnonymousIdentity
76 if s.Identity != "" { 83 if s.Identity != "" {
77 ident = s.Identity 84 ident = s.Identity
78 } 85 }
79 return &auth.User{ 86 return &auth.User{
80 Identity: ident, 87 Identity: ident,
81 Email: ident.Email(), 88 Email: ident.Email(),
82 } 89 }
83 } 90 }
84 91
85 // PeerIdentity is part of State interface. 92 // PeerIdentity is part of State interface.
86 func (s *FakeState) PeerIdentity() identity.Identity { 93 func (s *FakeState) PeerIdentity() identity.Identity {
87 if s.PeerIdentityOverride == "" { 94 if s.PeerIdentityOverride == "" {
88 return s.User().Identity 95 return s.User().Identity
89 } 96 }
90 return s.PeerIdentityOverride 97 return s.PeerIdentityOverride
91 } 98 }
92 99
93 // PeerIP is part of State interface. 100 // PeerIP is part of State interface.
94 func (s *FakeState) PeerIP() net.IP { 101 func (s *FakeState) PeerIP() net.IP {
95 if s.PeerIPOverride == nil { 102 if s.PeerIPOverride == nil {
96 return net.ParseIP("127.0.0.1") 103 return net.ParseIP("127.0.0.1")
97 } 104 }
98 return s.PeerIPOverride 105 return s.PeerIPOverride
99 } 106 }
OLDNEW
« no previous file with comments | « server/auth/authtest/method.go ('k') | server/auth/context.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698