func TestKeyEqual(t *testing.T) { first := &vsafe.Key{Id: 1} second := &vsafe.Key{Id: 1} third := &vsafe.Key{Id: 2} fourth := &vsafe.Key{Id: 1, Value: []byte{0x3}} var fifth *vsafe.Key var sixth *vsafe.Key if !first.Equal(first) { t.Error("Expected first and first to be equal.") } if !first.Equal(second) { t.Error("Expected first and second to be equal.") } if first.Equal(third) { t.Error("Expected first and third not to be equal.") } if first.Equal(fourth) { t.Error("Expected first and fouth not to be equal.") } if first.Equal(fifth) { t.Error("Expected first and fifth not to be equal.") } if fifth.Equal(first) { t.Error("Expected first and fifth not to be equal.") } if !fifth.Equal(sixth) { t.Error("Expected first and sixt to be equal.") } }
func TestKey(t *testing.T) { user := vsafe.User{Id: 1} var err error if err = user.Init("keep94", "somepassword"); err != nil { t.Fatalf("Error creating user: %v", err) } user2 := vsafe.User{Id: 2} if err = user2.Init("keep94", "somepassword"); err != nil { t.Fatalf("Error creating user: %v", err) } var key *vsafe.Key if key, err = user.VerifyPassword("somepassword"); err != nil { t.Fatalf("Verify password failed: %v", err) } var keyAgain *vsafe.Key if keyAgain, err = user.VerifyPassword("somepassword"); err != nil { t.Fatalf("Verify password failed: %v", err) } var key2 *vsafe.Key if key2, err = user2.VerifyPassword("somepassword"); err != nil { t.Fatalf("Verify password failed: %v", err) } if !key.Equal(keyAgain) { t.Errorf("Expected equal keys") } if key.Equal(key2) { t.Errorf("Expected unequal keys") } }
func TestUser(t *testing.T) { user := vsafe.User{Id: 1} var err error var key *vsafe.Key var key2 *vsafe.Key if err = user.Init("keep94", "somepassword"); err != nil { t.Fatalf("Error creating user: %v", err) } if key, err = user.VerifyPassword("somepassword"); err != nil { t.Fatalf("Verify password failed: %v", err) } if _, err = user.VerifyPassword("aardvark"); err != vsafe.ErrWrongPassword { t.Errorf("Expected wrong password, got %v", err) } user2 := vsafe.User{Id: 2} if err = user2.InitWithKey("keep94+admin", "foo", key); err != nil { t.Fatalf("Error creating user: %v", err) } if key2, err = user2.VerifyPassword("foo"); err != nil { t.Fatalf("Verify password failed: %v", err) } if !key2.Equal(key) { t.Error("key and key2 should be equal.") } if key.Id != 1 { t.Error("Expected key Id to be 1") } }