Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/resource_clients/key_value_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export class KeyValueStoreClient extends ResourceClient {
* If not provided, the URL will not expire.
*
* Any other options (like `limit` or `prefix`) will be included as query parameters in the URL.
*
*/
async createKeysPublicUrl(options: KeyValueClientListKeysOptions = {}, expiresInMillis?: number) {
ow(
Expand All @@ -111,7 +110,7 @@ export class KeyValueStoreClient extends ResourceClient {

const store = await this.get();

let createdPublicKeysUrl = new URL(this._url('items'));
let createdPublicKeysUrl = new URL(this._url('keys'));

if (store?.urlSigningSecretKey) {
const signature = createStorageContentSignature({
Expand Down
9 changes: 7 additions & 2 deletions test/datasets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,18 @@ describe('Dataset methods', () => {
const datasetId = 'id-with-secret-key';
const res = await client.dataset(datasetId).createItemsPublicUrl();

expect(new URL(res).searchParams.get('signature')).toBeDefined();
const url = new URL(res);
expect(url.searchParams.get('signature')).toBeDefined();
expect(url.pathname).toBe(`/v2/datasets/${datasetId}/items`);
});

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

expect(new URL(res).searchParams.get('signature')).toBeNull();
const url = new URL(res);
expect(url.searchParams.get('signature')).toBeNull();
expect(url.pathname).toBe(`/v2/datasets/${datasetId}/items`);
});

it('includes provided options (e.g., limit and prefix) as query parameters', async () => {
Expand All @@ -352,6 +356,7 @@ describe('Dataset methods', () => {
expect(itemsPublicUrl.searchParams.get('limit')).toBe('10');
expect(itemsPublicUrl.searchParams.get('offset')).toBe('5');
expect(itemsPublicUrl.searchParams.get('signature')).toBeDefined();
expect(itemsPublicUrl.pathname).toBe(`/v2/datasets/${datasetId}/items`);
});
});
});
Expand Down
9 changes: 7 additions & 2 deletions test/key_value_stores.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,18 @@ describe('Key-Value Store methods', () => {
const storeId = 'id-with-secret-key';
const res = await client.keyValueStore(storeId).createKeysPublicUrl();

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

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

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

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