auth

Paddy 2014-09-01 Parent:75cf37088852 Child:d89740a34654

31:88523dab00a5 Go to Latest

auth/token_test.go

Implement ClientStore in Memstore. Add the ClientStore interface implementation to Memstore. Change the ClientStore interface's UpdateClient function to take a new type, ClientChange, rather than enumerating the arguments in the function signature, which is a much cleaner interface. Add tests for the successful (works-as-intended) scenarios involving ClientStores. Ignore UpdateClient for now--I want to do tests that test every combination of ClientUpdate attributes being specified, to be sure that only the attributes specified are updated and that all the attributes specified are updated.

History
1 package auth
3 import (
4 "testing"
5 "time"
7 "secondbit.org/uuid"
8 )
10 var tokenStores = []TokenStore{NewMemstore()}
12 func TestTokenStoreSuccess(t *testing.T) {
13 token := Token{
14 AccessToken: "access",
15 RefreshToken: "refresh",
16 Created: time.Now(),
17 ExpiresIn: 3600,
18 TokenType: "bearer",
19 Scope: "scope",
20 ProfileID: uuid.NewID(),
21 }
22 for pos, store := range tokenStores {
23 err := store.SaveToken(token)
24 if err != nil {
25 t.Errorf("Error saving token in TokenStore #%d: %s", pos, err)
26 }
27 retrievedAccess, err := store.GetToken(token.AccessToken, false)
28 if err != nil {
29 t.Errorf("Error retrieving token in TokenStore #%d: %s", pos, err)
30 }
31 t.Log(retrievedAccess)
32 // TODO: compare retrievedAccess to token
33 retrievedRefresh, err := store.GetToken(token.RefreshToken, true)
34 if err != nil {
35 t.Errorf("Error retrieving refresh token in TokenStore #%d: %s", pos, err)
36 }
37 t.Log(retrievedRefresh)
38 // TODO: compare retrievedRefresh to token
39 retrievedProfile, err := store.GetTokensByProfileID(token.ProfileID, 25, 0)
40 if err != nil {
41 t.Errorf("Error retrieving token by profile in TokenStore #%d: %s", pos, err)
42 }
43 if len(retrievedProfile) != 1 {
44 t.Errorf("Expected 1 token retrieved by profile ID from TokenStore #%d, got %+v", pos, retrievedProfile)
45 }
46 // TODO: compare retrievedProfile to token
47 err = store.RemoveToken(token.AccessToken)
48 if err != nil {
49 t.Errorf("Error removing token in TokenStore #%d: %s", pos, err)
50 }
51 _, err = store.GetToken(token.AccessToken, false)
52 if err != ErrTokenNotFound {
53 t.Errorf("Expected ErrTokenNotFound from TokenStore #%d, got %s", pos, err)
54 }
55 _, err = store.GetToken(token.RefreshToken, true)
56 if err != ErrTokenNotFound {
57 t.Errorf("Expected ErrTokenNotFound from TokenStore #%d, got %s", pos, err)
58 }
59 retrievedProfile, err = store.GetTokensByProfileID(token.ProfileID, 25, 0)
60 if err != nil {
61 t.Errorf("Error retrieving token by profile in TokenStore #%d: %s", pos, err)
62 }
63 if len(retrievedProfile) != 0 {
64 t.Errorf("Expected list of 0 tokens from TokenStore #%d, got %+v", pos, retrievedProfile)
65 }
66 }
67 }