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
@@ -67,7 +67,7 @@ func TestStoreOnUpdateFiresWithNewInfo(t *testing.T) {
|
||||
|
||||
func TestHandlerRejectsMissingOrWrongSecret(t *testing.T) {
|
||||
store := NewStore(Info{})
|
||||
handler := Handler("s3cret", store)
|
||||
handler := Handler("test-internal-secret", store)
|
||||
body, _ := json.Marshal(Info{AuthGuardURL: "http://auth.example.com"})
|
||||
|
||||
cases := []string{"", "wrong"}
|
||||
@@ -127,14 +127,14 @@ func equalStrings(got, want []string) bool {
|
||||
|
||||
func TestHandlerAppliesPushedInfo(t *testing.T) {
|
||||
store := NewStore(Info{})
|
||||
handler := Handler("s3cret", store)
|
||||
handler := Handler("test-internal-secret", store)
|
||||
body, _ := json.Marshal(Info{
|
||||
AuthGuardURL: "http://auth.example.com", CarrierNodeURL: "http://carrier.example.com", CarrierNodeSecret: "carrier-secret",
|
||||
ContentScannerURL: "http://scanner.example.com/", ContentScannerSecret: "scanner-secret",
|
||||
})
|
||||
|
||||
req := httptest.NewRequest(http.MethodPut, "/api/core-services/internal", bytes.NewReader(body))
|
||||
req.Header.Set("X-Internal-Auth", "s3cret")
|
||||
req.Header.Set("X-Internal-Auth", "test-internal-secret")
|
||||
rec := httptest.NewRecorder()
|
||||
handler(rec, req)
|
||||
|
||||
@@ -152,7 +152,7 @@ func TestHandlerAppliesPushedInfo(t *testing.T) {
|
||||
|
||||
func TestHandlerRejectsNonHTTPURLsWithoutChangingStore(t *testing.T) {
|
||||
store := NewStore(Info{AuthGuardURL: "http://auth.example.com"})
|
||||
handler := Handler("s3cret", store)
|
||||
handler := Handler("test-internal-secret", store)
|
||||
for _, bad := range []Info{
|
||||
{AuthGuardURL: "javascript:alert(1)"},
|
||||
{AuthGuardURL: "auth.example.com"},
|
||||
@@ -161,7 +161,7 @@ func TestHandlerRejectsNonHTTPURLsWithoutChangingStore(t *testing.T) {
|
||||
} {
|
||||
body, _ := json.Marshal(bad)
|
||||
req := httptest.NewRequest(http.MethodPut, "/api/core-services/internal", bytes.NewReader(body))
|
||||
req.Header.Set("X-Internal-Auth", "s3cret")
|
||||
req.Header.Set("X-Internal-Auth", "test-internal-secret")
|
||||
rec := httptest.NewRecorder()
|
||||
handler(rec, req)
|
||||
if rec.Code != http.StatusBadRequest {
|
||||
@@ -172,3 +172,21 @@ func TestHandlerRejectsNonHTTPURLsWithoutChangingStore(t *testing.T) {
|
||||
t.Fatalf("store changed by a rejected push: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerRefusesAnUnusableSecret(t *testing.T) {
|
||||
for _, secret := range []string{"short", "SECRET", "change-me-to-a-long-random-value"} {
|
||||
store := NewStore(Info{})
|
||||
handler := Handler(secret, store)
|
||||
body, _ := json.Marshal(Info{AuthGuardURL: "http://auth.example.com"})
|
||||
req := httptest.NewRequest(http.MethodPut, "/api/core-services/internal", bytes.NewReader(body))
|
||||
req.Header.Set("X-Internal-Auth", secret)
|
||||
rec := httptest.NewRecorder()
|
||||
handler(rec, req)
|
||||
if rec.Code != http.StatusUnauthorized {
|
||||
t.Fatalf("secret %q: status = %d, want %d", secret, rec.Code, http.StatusUnauthorized)
|
||||
}
|
||||
if store.Get().AuthGuardURL != "" {
|
||||
t.Fatalf("secret %q: store changed despite a refused push", secret)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user