| OLD | NEW |
| 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 15 matching lines...) Expand all Loading... |
| 26 // | 26 // |
| 27 // identity.AnonymousIdentity if not set. | 27 // identity.AnonymousIdentity if not set. |
| 28 Identity identity.Identity | 28 Identity identity.Identity |
| 29 | 29 |
| 30 // IdentityGroups is list of groups the calling identity belongs to. | 30 // IdentityGroups is list of groups the calling identity belongs to. |
| 31 IdentityGroups []string | 31 IdentityGroups []string |
| 32 | 32 |
| 33 // Error if not nil is returned by IsMember checks. | 33 // Error if not nil is returned by IsMember checks. |
| 34 Error error | 34 Error error |
| 35 | 35 |
| 36 // FakeDB is a mock authdb.DB implementation to use. |
| 37 // |
| 38 // If not nil, overrides 'IdentityGroups' and 'Error'. |
| 39 FakeDB authdb.DB |
| 40 |
| 36 // PeerIdentityOverride may be set for PeerIdentity() to return custom v
alue. | 41 // PeerIdentityOverride may be set for PeerIdentity() to return custom v
alue. |
| 37 // | 42 // |
| 38 // By default PeerIdentity() returns Identity (i.e. no delegation is | 43 // By default PeerIdentity() returns Identity (i.e. no delegation is |
| 39 // happening). | 44 // happening). |
| 40 PeerIdentityOverride identity.Identity | 45 PeerIdentityOverride identity.Identity |
| 41 | 46 |
| 42 // PeerIPOverride may be set for PeerIP() to return custom value. | 47 // PeerIPOverride may be set for PeerIP() to return custom value. |
| 43 // | 48 // |
| 44 // By default PeerIP() returns "127.0.0.1". | 49 // By default PeerIP() returns "127.0.0.1". |
| 45 PeerIPOverride net.IP | 50 PeerIPOverride net.IP |
| 46 } | 51 } |
| 47 | 52 |
| 48 var _ auth.State = (*FakeState)(nil) | 53 var _ auth.State = (*FakeState)(nil) |
| 49 | 54 |
| 50 // DB is part of State interface. | 55 // DB is part of State interface. |
| 51 func (s *FakeState) DB() authdb.DB { | 56 func (s *FakeState) DB() authdb.DB { |
| 57 if s.FakeDB != nil { |
| 58 return s.FakeDB |
| 59 } |
| 52 return &FakeErroringDB{ | 60 return &FakeErroringDB{ |
| 53 FakeDB: FakeDB{s.User().Identity: s.IdentityGroups}, | 61 FakeDB: FakeDB{s.User().Identity: s.IdentityGroups}, |
| 54 Error: s.Error, | 62 Error: s.Error, |
| 55 } | 63 } |
| 56 } | 64 } |
| 57 | 65 |
| 58 // Method is part of State interface. | 66 // Method is part of State interface. |
| 59 func (s *FakeState) Method() auth.Method { | 67 func (s *FakeState) Method() auth.Method { |
| 60 return &FakeAuth{ | 68 return &FakeAuth{ |
| 61 User: s.User(), | 69 User: s.User(), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 82 return s.PeerIdentityOverride | 90 return s.PeerIdentityOverride |
| 83 } | 91 } |
| 84 | 92 |
| 85 // PeerIP is part of State interface. | 93 // PeerIP is part of State interface. |
| 86 func (s *FakeState) PeerIP() net.IP { | 94 func (s *FakeState) PeerIP() net.IP { |
| 87 if s.PeerIPOverride == nil { | 95 if s.PeerIPOverride == nil { |
| 88 return net.ParseIP("127.0.0.1") | 96 return net.ParseIP("127.0.0.1") |
| 89 } | 97 } |
| 90 return s.PeerIPOverride | 98 return s.PeerIPOverride |
| 91 } | 99 } |
| OLD | NEW |