Skip to content

Commit a48ec58

Browse files
authored
fix: KV store createKeysPublicUrl wrong URL (#724)
After release of new methods `KeyValueStore.createKeysPublicUrl` and `Dataset.createItemsPublicUrl` ([PR here](#720)), I noticed that in `KeyValueStore.createKeysPublicUrl` I used incorrect path `items` instead of `keys`. This PR fixes URL path and improves tests.
1 parent a1c5d6b commit a48ec58

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/resource_clients/key_value_store.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ export class KeyValueStoreClient extends ResourceClient {
9696
* If not provided, the URL will not expire.
9797
*
9898
* Any other options (like `limit` or `prefix`) will be included as query parameters in the URL.
99-
*
10099
*/
101100
async createKeysPublicUrl(options: KeyValueClientListKeysOptions = {}, expiresInMillis?: number) {
102101
ow(
@@ -111,7 +110,7 @@ export class KeyValueStoreClient extends ResourceClient {
111110

112111
const store = await this.get();
113112

114-
let createdPublicKeysUrl = new URL(this._url('items'));
113+
let createdPublicKeysUrl = new URL(this._url('keys'));
115114

116115
if (store?.urlSigningSecretKey) {
117116
const signature = createStorageContentSignature({

test/datasets.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,18 @@ describe('Dataset methods', () => {
333333
const datasetId = 'id-with-secret-key';
334334
const res = await client.dataset(datasetId).createItemsPublicUrl();
335335

336-
expect(new URL(res).searchParams.get('signature')).toBeDefined();
336+
const url = new URL(res);
337+
expect(url.searchParams.get('signature')).toBeDefined();
338+
expect(url.pathname).toBe(`/v2/datasets/${datasetId}/items`);
337339
});
338340

339341
it('should not include a signature in the URL when the caller lacks permission to access the signing secret key', async () => {
340342
const datasetId = 'some-id';
341343
const res = await client.dataset(datasetId).createItemsPublicUrl();
342344

343-
expect(new URL(res).searchParams.get('signature')).toBeNull();
345+
const url = new URL(res);
346+
expect(url.searchParams.get('signature')).toBeNull();
347+
expect(url.pathname).toBe(`/v2/datasets/${datasetId}/items`);
344348
});
345349

346350
it('includes provided options (e.g., limit and prefix) as query parameters', async () => {
@@ -352,6 +356,7 @@ describe('Dataset methods', () => {
352356
expect(itemsPublicUrl.searchParams.get('limit')).toBe('10');
353357
expect(itemsPublicUrl.searchParams.get('offset')).toBe('5');
354358
expect(itemsPublicUrl.searchParams.get('signature')).toBeDefined();
359+
expect(itemsPublicUrl.pathname).toBe(`/v2/datasets/${datasetId}/items`);
355360
});
356361
});
357362
});

test/key_value_stores.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,14 +559,18 @@ describe('Key-Value Store methods', () => {
559559
const storeId = 'id-with-secret-key';
560560
const res = await client.keyValueStore(storeId).createKeysPublicUrl();
561561

562-
expect(new URL(res).searchParams.get('signature')).toBeDefined();
562+
const url = new URL(res);
563+
expect(url.searchParams.get('signature')).toBeDefined();
564+
expect(url.pathname).toBe(`/v2/key-value-stores/${storeId}/keys`);
563565
});
564566

565567
it('should not include a signature in the URL when the caller lacks permission to access the signing secret key', async () => {
566568
const storeId = 'some-id';
567569
const res = await client.keyValueStore(storeId).createKeysPublicUrl();
568570

569-
expect(new URL(res).searchParams.get('signature')).toBeNull();
571+
const url = new URL(res);
572+
expect(url.searchParams.get('signature')).toBeNull();
573+
expect(url.pathname).toBe(`/v2/key-value-stores/${storeId}/keys`);
570574
});
571575

572576
it('includes provided options (e.g., limit and prefix) as query parameters', async () => {
@@ -577,6 +581,7 @@ describe('Key-Value Store methods', () => {
577581
expect(keysPublicUrl.searchParams.get('limit')).toBe('10');
578582
expect(keysPublicUrl.searchParams.get('prefix')).toBe('prefix');
579583
expect(keysPublicUrl.searchParams.get('signature')).toBeDefined();
584+
expect(keysPublicUrl.pathname).toBe(`/v2/key-value-stores/${storeId}/keys`);
580585
});
581586
});
582587
});

0 commit comments

Comments
 (0)