Skip to content

Commit

Permalink
fix: remove extra slash when constructing user storage url (#4702)
Browse files Browse the repository at this point in the history
## Explanation

This PR solves the bug of adding extra slash when user storage url is
generated

## References

## Changelog

### `@metamask/profile-sync-controller`

- **FIXED**: remove extra slash when constructing user storage url

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate

---------

Co-authored-by: Mathieu Artu <mathieu.artu@consensys.net>
  • Loading branch information
dovydas55 and mathieuartu authored Sep 13, 2024
1 parent ccd95c8 commit 57a722e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
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

0 comments on commit 57a722e

Please sign in to comment.