Implement postgres version of scopeStore.
Update the authd server to use postgres as its scopeStore, instead of memstore.
panic when starting the authd server if the CreateScopes call fails. This
should, ideally, ignore ErrScopeAlreadyExists errors, but does not as of this
commit.
Update the simple.gotmpl template to properly display scopes, after switching to
the Scope type instead of simply passing around the string the client supplied
broke the template and I never bothered fixing it.
Update the updateScopes method on the scopeStore (and the corresponding
UpdateScopes method on the Context type) to be updateScope/UpdateScope.
Operating on several scopes at a time like that is simply too challenging in
SQL and I can't justify the complexity with a use case.
Add a helper method to ScopeChange called Empty(), which returns true if the
ScopeChange is full of nil values.
Remove the ID from the ScopeChange type, because we're no longer accepting
multiple ScopeChange types in UpdateScope, so we can supply that information
outside the ScopeChange, which matches the rest of our update* methods.
Correct our tests in scope_test.go to correctly use the updateScope method
instead of the old updateScopes method. This generally just resulted in calling
updateScope multiple times, as opposed to just once.
Add a scope table initialization to the sql/postgres_init.sql script.
7 "code.secondbit.org/uuid.hg"
10 var sessionStores = []sessionStore{NewMemstore()}
12 func compareSessions(session1, session2 Session) (success bool, field string, val1, val2 interface{}) {
13 if session1.ID != session2.ID {
14 return false, "ID", session1.ID, session2.ID
16 if session1.IP != session2.IP {
17 return false, "IP", session1.IP, session2.IP
19 if session1.UserAgent != session2.UserAgent {
20 return false, "UserAgent", session1.UserAgent, session2.UserAgent
22 if !session1.ProfileID.Equal(session2.ProfileID) {
23 return false, "ProfileID", session1.ProfileID, session2.ProfileID
25 if !session1.Created.Equal(session2.Created) {
26 return false, "Created", session1.Created, session2.Created
28 if !session1.Expires.Equal(session2.Expires) {
29 return false, "Expires", session1.Expires, session2.Expires
31 if session1.Login != session2.Login {
32 return false, "Login", session1.Login, session2.Login
34 if session1.Active != session2.Active {
35 return false, "Active", session1.Active, session2.Active
37 if session1.CSRFToken != session2.CSRFToken {
38 return false, "CSRFToken", session1.CSRFToken, session2.CSRFToken
40 return true, "", nil, nil
43 func TestSessionStoreSuccess(t *testing.T) {
46 ID: uuid.NewID().String() + uuid.NewID().String(),
48 UserAgent: "TestRunner",
49 ProfileID: uuid.NewID(),
50 Created: time.Now().Round(time.Millisecond),
51 Login: "test@example.com",
54 for _, store := range sessionStores {
55 context := Context{sessions: store}
56 err := context.CreateSession(session)
58 t.Errorf("Error saving session to %T: %s", store, err)
60 err = context.CreateSession(session)
61 if err != ErrSessionAlreadyExists {
62 t.Errorf("Expected ErrSessionAlreadyExists from %T, got %s", store, err)
64 retrieved, err := context.GetSession(session.ID)
66 t.Errorf("Error retrieving session from %T: %s", store, err)
68 success, field, expectation, result := compareSessions(session, retrieved)
70 t.Errorf("Expected field %s to be %v, but got %v from %T", field, expectation, result, store)
72 retrievedList, err := context.ListSessions(session.ProfileID, time.Time{}, 10)
74 t.Errorf("Error retrieving sessions by profile from %T: %s", store, err)
76 if len(retrievedList) != 1 {
77 t.Errorf("Expected 1 session retrieved by profile from %T, got %d", store, len(retrievedList))
79 success, field, expectation, result = compareSessions(session, retrievedList[0])
81 t.Errorf("Expected field %s to be %v, but got %v from %T", field, expectation, result, store)
83 err = context.RemoveSession(session.ID)
85 t.Errorf("Error removing session from %T: %s", store, err)
87 retrieved, err = context.GetSession(session.ID)
88 if err != ErrSessionNotFound {
89 t.Errorf("Expected ErrSessionNotFound from %T, got %s", store, err)
91 retrievedList, err = context.ListSessions(session.ProfileID, time.Time{}, 10)
93 t.Errorf("Error retrieving sessions by profile from %T: %s", store, err)
95 if len(retrievedList) != 0 {
96 t.Errorf("Expected 0 sessions retrieved by profile from %T, got %d", store, len(retrievedList))
98 err = context.RemoveSession(session.ID)
99 if err != ErrSessionNotFound {
100 t.Errorf("Expected ErrSessionNotFound from %T, got %s", store, err)
105 // BUG(paddy): We need to test the CreateSessionHandler.
106 // BUG(paddy): We need to test the credentialsValidate function.