auth

Paddy 2014-09-27 Parent:c6ace3d27c6f Child:d78418fb9f56

47:85f1baf7a9ac Browse Files

Add basic test for retrieving profiles by login. Add a basic test for retrieving profiles from ProfileStores by a passed login. The test is very basic, in that it doesn't test for deleted logins, deleted profiles, etc. But it at least tests that in ordinary circumstances, things work as they're supposed to.

profile_test.go

     1.1 --- a/profile_test.go	Sat Sep 27 21:41:39 2014 -0400
     1.2 +++ b/profile_test.go	Sat Sep 27 22:25:06 2014 -0400
     1.3 @@ -361,3 +361,46 @@
     1.4  		}
     1.5  	}
     1.6  }
     1.7 +
     1.8 +func TestProfileStoreLoginRetrieval(t *testing.T) {
     1.9 +	t.Parallel()
    1.10 +	profile := Profile{
    1.11 +		ID:                     uuid.NewID(),
    1.12 +		Name:                   "name",
    1.13 +		Passphrase:             "passphrase",
    1.14 +		Iterations:             10000,
    1.15 +		Salt:                   "salt",
    1.16 +		PassphraseScheme:       1,
    1.17 +		Compromised:            false,
    1.18 +		LockedUntil:            time.Now().Add(time.Hour),
    1.19 +		PassphraseReset:        "passphrase reset",
    1.20 +		PassphraseResetCreated: time.Now(),
    1.21 +		Created:                time.Now(),
    1.22 +		LastSeen:               time.Now(),
    1.23 +	}
    1.24 +	login := Login{
    1.25 +		Type:      "type",
    1.26 +		Value:     "value",
    1.27 +		ProfileID: profile.ID,
    1.28 +		Created:   time.Now().Add(-1 * time.Hour),
    1.29 +		LastUsed:  time.Now().Add(-1 * time.Minute),
    1.30 +	}
    1.31 +	for _, store := range profileStores {
    1.32 +		err := store.SaveProfile(profile)
    1.33 +		if err != nil {
    1.34 +			t.Errorf("Error saving profile in %T: %s", store, err)
    1.35 +		}
    1.36 +		err = store.AddLogin(login)
    1.37 +		if err != nil {
    1.38 +			t.Errorf("Error storing login in %T: %s", store, err)
    1.39 +		}
    1.40 +		retrieved, err := store.GetProfileByLogin(login.Type, login.Value)
    1.41 +		if err != nil {
    1.42 +			t.Errorf("Error retrieving profile by login from %T: %s", store, err)
    1.43 +		}
    1.44 +		match, field, expectation, result := compareProfiles(profile, retrieved)
    1.45 +		if !match {
    1.46 +			t.Errorf("Expected `%v` in the `%s` field of profile retrieved from %T, got `%v`", expectation, field, store, result)
    1.47 +		}
    1.48 +	}
    1.49 +}