Skip to content

Commit 7cd57a2

Browse files
committed
fix: Flaky tests after dependencies update
1 parent 1cd6153 commit 7cd57a2

File tree

3 files changed

+38
-48
lines changed

3 files changed

+38
-48
lines changed

tests/testutils/test_utils.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,15 @@ type TestSetup struct {
110110
// NewSetup returns a new TestSetup
111111
// name is used to prevent bug when tests are run in parallel
112112
func NewSetup(t testing.TB, name string) *TestSetup {
113-
// Replace underscores with hyphens - underscores are invalid in domain names
114-
// and cause Go's net/http to reject cookies with such domains
115-
sanitizedName := strings.ReplaceAll(strings.ToLower(name), "_", "-")
113+
// Remove underscores and hyphens - underscores are invalid in domain names
114+
// and cause Go's net/http to reject cookies. Hyphens are stripped by the
115+
// OIDC code (see buildDomain), so we avoid them to keep domains consistent.
116+
sanitizedName := strings.ReplaceAll(strings.ToLower(name), "_", "")
117+
sanitizedName = strings.ReplaceAll(sanitizedName, "-", "")
116118
setup := TestSetup{
117119
name: name,
118120
t: t,
119-
host: sanitizedName + "-" + utils.RandomString(10) + ".cozy.local",
121+
host: sanitizedName + utils.RandomString(10) + ".cozy.local",
120122
cleanup: func() {},
121123
}
122124

web/sharings/drives_test.go

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,50 +2223,26 @@ func TestSharedDriveGroupDynamicMembership(t *testing.T) {
22232223
members.Value(1).Object().Value("only_in_groups").IsEqual(true)
22242224
members.Value(1).Object().Value("groups").Array().Value(0).IsEqual(0)
22252225

2226-
// Step 6: Set up Alice's instance to know about the owner's URL for the sharing (for auto-accept)
2227-
FakeOwnerInstanceForSharing(t, aliceInstance, tsOwner.URL, sharingID)
2228-
2229-
// Step 7: Wait for Alice's sharing to be auto-accepted
2226+
// Step 6: Wait for the sharing to exist on Alice's instance, then set up the owner's URL
22302227
eAlice := httpexpect.Default(t, tsAlice.URL)
2231-
isMemberReady := func(e *httpexpect.Expect, token, email string) bool {
2232-
resp := e.GET("/sharings/"+sharingID).
2233-
WithHeader("Authorization", "Bearer "+token).
2228+
require.Eventually(t, func() bool {
2229+
resp := eAlice.GET("/sharings/"+sharingID).
2230+
WithHeader("Authorization", "Bearer "+aliceAppToken).
22342231
Expect()
2235-
if resp.Raw().StatusCode != http.StatusOK {
2236-
return false
2237-
}
2232+
return resp.Raw().StatusCode == 200
2233+
}, 10*time.Second, 500*time.Millisecond, "Alice's sharing should exist")
22382234

2239-
raw := resp.JSON(httpexpect.ContentOpts{MediaType: "application/vnd.api+json"}).Object().Raw()
2240-
data, ok := raw["data"].(map[string]interface{})
2241-
if !ok {
2242-
return false
2243-
}
2244-
attrs, ok := data["attributes"].(map[string]interface{})
2245-
if !ok {
2246-
return false
2247-
}
2248-
members, ok := attrs["members"].([]interface{})
2249-
if !ok {
2250-
return false
2251-
}
2252-
2253-
for _, member := range members {
2254-
memberObj, ok := member.(map[string]interface{})
2255-
if !ok {
2256-
continue
2257-
}
2258-
memberEmail, _ := memberObj["email"].(string)
2259-
memberStatus, _ := memberObj["status"].(string)
2260-
if memberEmail == email {
2261-
return memberStatus == sharing.MemberStatusReady
2262-
}
2263-
}
2235+
// Now update the owner's URL in Alice's sharing document
2236+
FakeOwnerInstanceForSharing(t, aliceInstance, tsOwner.URL, sharingID)
22642237

2265-
return false
2266-
}
2238+
// Step 7: Wait for Alice's sharing to be auto-accepted
22672239
require.Eventually(t, func() bool {
2268-
return isMemberReady(eAlice, aliceAppToken, "alice@example.com")
2269-
}, 10*time.Second, 500*time.Millisecond, "Alice's sharing should be auto-accepted")
2240+
var s sharing.Sharing
2241+
if err := couchdb.GetDoc(aliceInstance, consts.Sharings, sharingID, &s); err != nil {
2242+
return false
2243+
}
2244+
return s.Active
2245+
}, 10*time.Second, 500*time.Millisecond, "Alice's sharing should be auto-accepted and active")
22702246

22712247
// Step 8: Verify Alice can access the file
22722248
eAlice.GET("/sharings/drives/"+sharingID+"/"+fileID).
@@ -2294,15 +2270,27 @@ func TestSharedDriveGroupDynamicMembership(t *testing.T) {
22942270
require.True(t, s.Members[2].OnlyInGroups)
22952271
require.Equal(t, []int{0}, s.Members[2].Groups)
22962272

2297-
// Step 13: Set up Bob's instance to know about the owner's URL for the sharing
2273+
// Step 13: Wait for the sharing to exist on Bob's instance, then set up the owner's URL
2274+
eBob := httpexpect.Default(t, tsBob.URL)
2275+
require.Eventually(t, func() bool {
2276+
resp := eBob.GET("/sharings/"+sharingID).
2277+
WithHeader("Authorization", "Bearer "+bobAppToken).
2278+
Expect()
2279+
return resp.Raw().StatusCode == 200
2280+
}, 10*time.Second, 500*time.Millisecond, "Bob's sharing should exist")
2281+
2282+
// Now update the owner's URL in Bob's sharing document
22982283
FakeOwnerInstanceForSharing(t, bobInstance, tsOwner.URL, sharingID)
22992284

23002285
// Step 14: Verify Bob can access the shared drive after auto-accept
23012286
// Wait for the sharing to be auto-accepted on Bob's side
2302-
eBob := httpexpect.Default(t, tsBob.URL)
23032287
require.Eventually(t, func() bool {
2304-
return isMemberReady(eBob, bobAppToken, "bob@example.com")
2305-
}, 10*time.Second, 500*time.Millisecond, "Bob's sharing should be auto-accepted")
2288+
var s sharing.Sharing
2289+
if err := couchdb.GetDoc(bobInstance, consts.Sharings, sharingID, &s); err != nil {
2290+
return false
2291+
}
2292+
return s.Active
2293+
}, 10*time.Second, 500*time.Millisecond, "Bob's sharing should be auto-accepted and active")
23062294

23072295
// Step 15: Verify Bob can access the file in the shared drive
23082296
eBob.GET("/sharings/drives/"+sharingID+"/"+fileID).

web/shortcuts/shortcuts_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestShortcuts(t *testing.T) {
7171

7272
cozyMeta := attrs.Value("cozyMetadata").Object()
7373
cozyMeta.Value("createdAt").String().DateTime(time.RFC3339)
74-
cozyMeta.Value("createdOn").String().Contains("https://testshortcuts-")
74+
cozyMeta.Value("createdOn").String().Contains("https://testshortcuts")
7575

7676
target := attrs.Value("metadata").Object().Value("target").Object()
7777
target.ValueEqual("app", "photos")

0 commit comments

Comments
 (0)