Skip to content
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

fix: remove extra slash when constructing user storage url #4702

Merged
merged 3 commits into from
Sep 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getMockUserStorageEndpoint = (
return `${USER_STORAGE_ENDPOINT}/${path}`;
}

return `${USER_STORAGE_ENDPOINT}${createEntryPath(
return `${USER_STORAGE_ENDPOINT}/${createEntryPath(
path as UserStoragePathWithFeatureAndKey,
MOCK_STORAGE_KEY,
)}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import { getFeatureAndKeyFromPath, USER_STORAGE_SCHEMA } from './schema';
import {
createEntryPath,
getFeatureAndKeyFromPath,
USER_STORAGE_SCHEMA,
} from './schema';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type ErroneousUserStoragePath = any;

describe('user-storage/schema.ts', () => {
describe('getFeatureAndKeyFromPath', () => {
it('should correctly construct user storage url', () => {
expect(
createEntryPath(
'notifications.notificationSettings',
'dbdc994804e591f7bef6695e525543712358dd5c952bd257560b629887972588',
),
).toBe(
'notifications/2072257b71d53b6cb8e72bab8e801e3d66faa0d5e1b822c88af466127e5e763b',
);
});

it('should throw error if the feature.key format is incorrect', () => {
const path = 'feature/key';
expect(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ export function createEntryPath(
const { feature, key } = getFeatureAndKeyFromPath(path);
const hashedKey = createSHA256Hash(key + storageKey);

return `/${feature}/${hashedKey}`;
return `${feature}/${hashedKey}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function getUserStorage(
const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;

const encryptedPath = createEntryPath(path, storageKey);
const url = new URL(`${USER_STORAGE_ENDPOINT}${encryptedPath}`);
const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);

const userStorageResponse = await fetch(url.toString(), {
headers: {
Expand Down Expand Up @@ -172,7 +172,7 @@ export async function upsertUserStorage(
nativeScryptCrypto,
);
const encryptedPath = createEntryPath(path, storageKey);
const url = new URL(`${USER_STORAGE_ENDPOINT}${encryptedPath}`);
const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);

const res = await fetch(url.toString(), {
method: 'PUT',
Expand Down
Loading