-
Notifications
You must be signed in to change notification settings - Fork 1
Allow access authorities to view unlisted tracks #760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -62,3 +62,29 @@ func TestGetTracksExcludesAccessAuthorities(t *testing.T) { | |||||||||||||||||||||||||||||||
| assert.Equal(t, "T1", resp.Data[0].Title.String) | ||||||||||||||||||||||||||||||||
| assert.Equal(t, []string{gateWallet}, resp.Data[0].AccessAuthorities) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| func TestGetUnlistedTrackWithAccessAuthority(t *testing.T) { | ||||||||||||||||||||||||||||||||
| app := testAppWithFixtures(t) | ||||||||||||||||||||||||||||||||
| ctx := context.Background() | ||||||||||||||||||||||||||||||||
| require.NotNil(t, app.writePool, "test requires write pool") | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| gateWallet := "0x7d273271690538cf855e5b3002a0dd8c154bb060" | ||||||||||||||||||||||||||||||||
| // Make track 100 both unlisted and gated by access_authorities | ||||||||||||||||||||||||||||||||
| _, err := app.writePool.Exec(ctx, `UPDATE tracks SET is_unlisted = true, access_authorities = ARRAY[$1]::text[] WHERE track_id = 100 AND is_current = true`, gateWallet) | ||||||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| var resp struct { | ||||||||||||||||||||||||||||||||
| Data []dbv1.Track | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Without auth: unlisted + gated track must not be returned | ||||||||||||||||||||||||||||||||
| status, _ := testGet(t, app, "/v1/full/tracks?id=eYZmn", &resp) | ||||||||||||||||||||||||||||||||
| assert.Equal(t, 200, status) | ||||||||||||||||||||||||||||||||
| assert.Len(t, resp.Data, 0, "unlisted track with access_authorities must not be returned when unauthenticated") | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // With auth signed by access authority: unlisted track must be returned | ||||||||||||||||||||||||||||||||
| status, _ = testGetWithWallet(t, app, "/v1/full/tracks?id=eYZmn", gateWallet, &resp) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+80
to
+86
|
||||||||||||||||||||||||||||||||
| // Without auth: unlisted + gated track must not be returned | |
| status, _ := testGet(t, app, "/v1/full/tracks?id=eYZmn", &resp) | |
| assert.Equal(t, 200, status) | |
| assert.Len(t, resp.Data, 0, "unlisted track with access_authorities must not be returned when unauthenticated") | |
| // With auth signed by access authority: unlisted track must be returned | |
| status, _ = testGetWithWallet(t, app, "/v1/full/tracks?id=eYZmn", gateWallet, &resp) | |
| // Use the non-full tracks endpoint so IncludeUnlisted is not force-enabled. | |
| // Without auth: unlisted + gated track must not be returned. | |
| status, _ := testGet(t, app, "/v1/tracks?id=eYZmn", &resp) | |
| assert.Equal(t, 200, status) | |
| assert.Len(t, resp.Data, 0, "unlisted track with access_authorities must not be returned when unauthenticated") | |
| // With auth signed by access authority: unlisted track must be returned. | |
| status, _ = testGetWithWallet(t, app, "/v1/tracks?id=eYZmn", gateWallet, &resp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The access-authority wallet match (
EXISTS (SELECT 1 FROM unnest(t.access_authorities) ...)) is computed twice now: once inside theis_unlistedOR clause and again in the existingAND (t.access_authorities IS NULL OR ...)gate below. Since theANDclause already enforces the wallet match wheneveraccess_authoritiesis non-NULL, the OR clause only needs to check that@authed_walletis set andt.access_authoritiesis non-NULL; duplicating theEXISTS/unnestadds per-row work and makes the predicate harder to maintain.