auth
auth/client.go
Update CheckEndpoints for strict checking, add CountEndpoints. Create a "strict" mode for CheckEndpoints that will only return true on an exact match, and update the memstore implementation accordingly. Add tests to make sure that the strict mode is adhered to. We need this mode because in certain situations (e.g., the client has more than one endpoint registered), the spec demands a full-string comparison. Add a CountEndpoints method to the ClientStore that will return the number of endpoints registered for a specific client. As we just mentioned, the rules for how a redirect URI is validated depend upon the number of endpoints a client has registered, so we need to be able to get at that number.
1.1 --- a/client.go Thu Oct 16 00:18:14 2014 -0400 1.2 +++ b/client.go Wed Oct 22 00:26:39 2014 -0400 1.3 @@ -125,8 +125,9 @@ 1.4 1.5 AddEndpoint(client uuid.ID, endpoint Endpoint) error 1.6 RemoveEndpoint(client, endpoint uuid.ID) error 1.7 - CheckEndpoint(client uuid.ID, endpoint string) (bool, error) 1.8 + CheckEndpoint(client uuid.ID, endpoint string, strict bool) (bool, error) 1.9 ListEndpoints(client uuid.ID, num, offset int) ([]Endpoint, error) 1.10 + CountEndpoints(client uuid.ID) (int64, error) 1.11 } 1.12 1.13 func (m *Memstore) GetClient(id uuid.ID) (Client, error) { 1.14 @@ -226,11 +227,13 @@ 1.15 return nil 1.16 } 1.17 1.18 -func (m *Memstore) CheckEndpoint(client uuid.ID, endpoint string) (bool, error) { 1.19 +func (m *Memstore) CheckEndpoint(client uuid.ID, endpoint string, strict bool) (bool, error) { 1.20 m.endpointLock.RLock() 1.21 defer m.endpointLock.RUnlock() 1.22 for _, candidate := range m.endpoints[client.String()] { 1.23 - if strings.HasPrefix(endpoint, candidate.URI.String()) { 1.24 + if !strict && strings.HasPrefix(endpoint, candidate.URI.String()) { 1.25 + return true, nil 1.26 + } else if strict && endpoint == candidate.URI.String() { 1.27 return true, nil 1.28 } 1.29 } 1.30 @@ -242,3 +245,9 @@ 1.31 defer m.endpointLock.RUnlock() 1.32 return m.endpoints[client.String()], nil 1.33 } 1.34 + 1.35 +func (m *Memstore) CountEndpoints(client uuid.ID) (int64, error) { 1.36 + m.endpointLock.RLock() 1.37 + defer m.endpointLock.RUnlock() 1.38 + return int64(len(m.endpoints[client.String()])), nil 1.39 +}