feat(sync): paginate Android sync with change tokens
This commit is contained in:
1 parent
0ff94f9b10
commit
97c237be80
76 files changed
+3401
-851
No files matched your search
@@ -21,6 +21,8 @@ type authContract struct {
|
||||
Hashes []struct {
|
||||
Name string `json:"name"`
|
||||
Hash string `json:"hash"`
|
||||
Password string `json:"password"`
|
||||
WrongPassword string `json:"wrongPassword"`
|
||||
Verifies map[string]bool `json:"verifies"`
|
||||
NeedsUpgrade map[string]bool `json:"needsUpgrade"`
|
||||
} `json:"hashes"`
|
||||
@@ -36,6 +38,7 @@ type authContract struct {
|
||||
Unix int64 `json:"unix"`
|
||||
Code string `json:"code"`
|
||||
Secret *string `json:"secret"`
|
||||
MatchedStep *int64 `json:"matchedStep"`
|
||||
Valid bool `json:"valid"`
|
||||
} `json:"cases"`
|
||||
} `json:"totp"`
|
||||
@@ -71,21 +74,29 @@ func TestContractPasswordHashes(t *testing.T) {
|
||||
contract := loadContract(t)
|
||||
for _, entry := range contract.Password.Hashes {
|
||||
t.Run(entry.Name, func(t *testing.T) {
|
||||
if got := VerifyPassword(entry.Hash, contract.Password.Plaintext); got != entry.Verifies["go"] {
|
||||
password := entry.Password
|
||||
if password == "" {
|
||||
password = contract.Password.Plaintext
|
||||
}
|
||||
wrongPassword := entry.WrongPassword
|
||||
if wrongPassword == "" {
|
||||
wrongPassword = contract.Password.WrongPassword
|
||||
}
|
||||
if got := VerifyPassword(entry.Hash, password); got != entry.Verifies["go"] {
|
||||
t.Errorf("VerifyPassword = %v, want %v", got, entry.Verifies["go"])
|
||||
}
|
||||
if VerifyPassword(entry.Hash, contract.Password.WrongPassword) {
|
||||
if VerifyPassword(entry.Hash, wrongPassword) {
|
||||
t.Error("VerifyPassword accepted the wrong password")
|
||||
}
|
||||
if want, ok := entry.NeedsUpgrade["go"]; ok {
|
||||
if got := PasswordHashNeedsUpgrade(entry.Hash); got != want {
|
||||
t.Errorf("PasswordHashNeedsUpgrade = %v, want %v", got, want)
|
||||
}
|
||||
valid, upgraded, err := VerifyAndUpgradePassword(entry.Hash, contract.Password.Plaintext)
|
||||
valid, upgraded, err := VerifyAndUpgradePassword(entry.Hash, password)
|
||||
if err != nil || !valid || (upgraded != "") != want {
|
||||
t.Errorf("VerifyAndUpgradePassword = %v, upgraded %v, %v; want valid with an upgrade = %v", valid, upgraded != "", err, want)
|
||||
}
|
||||
if upgraded != "" && (!strings.HasPrefix(upgraded, bcryptScheme) || !VerifyPassword(upgraded, contract.Password.Plaintext)) {
|
||||
if upgraded != "" && (!strings.HasPrefix(upgraded, bcryptScheme) && !strings.HasPrefix(upgraded, bcryptSHA256Scheme) || !VerifyPassword(upgraded, password)) {
|
||||
t.Errorf("the upgraded hash %q is not a verifiable current-scheme hash", upgraded)
|
||||
}
|
||||
}
|
||||
@@ -109,9 +120,19 @@ func TestContractTOTP(t *testing.T) {
|
||||
if entry.Secret != nil {
|
||||
secret = *entry.Secret
|
||||
}
|
||||
if got := VerifyTOTP(secret, entry.Code, time.Unix(entry.Unix, 0)); got != entry.Valid {
|
||||
step, got := VerifyTOTP(secret, entry.Code, time.Unix(entry.Unix, 0))
|
||||
if got != entry.Valid {
|
||||
t.Errorf("VerifyTOTP = %v, want %v", got, entry.Valid)
|
||||
}
|
||||
if got {
|
||||
want := entry.Unix / 30
|
||||
if entry.MatchedStep != nil {
|
||||
want = *entry.MatchedStep
|
||||
}
|
||||
if step != want {
|
||||
t.Errorf("VerifyTOTP matched step %d, want %d", step, want)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user