Skip to content

Commit

Permalink
fix: fix coreNode error when fetching public data with no user session
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsan-javaid authored and reedrosenbluth committed Aug 3, 2021
1 parent f3cf946 commit 144754b
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/storage/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ function normalizeOptions<T>(
}
const sessionData = userSession.store.getSessionData();
// Use the user specified coreNode if available, otherwise use the app specified coreNode.
const configuredCoreNode = sessionData.userData!.coreNode || userSession.appConfig.coreNode;
const configuredCoreNode = sessionData.userData?.coreNode || userSession.appConfig.coreNode;
if (configuredCoreNode) {
opts.zoneFileLookupURL = `${configuredCoreNode}${NAME_LOOKUP_PATH}`;
}
Expand Down
109 changes: 109 additions & 0 deletions packages/storage/tests/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,115 @@ test('getFile unencrypted, unsigned', async () => {
expect(JSON.parse(<string>file)).toEqual(fileContent);
});

test('getFile without user session', async () => {
const path = 'file.json';
const appConfig = new AppConfig(['store_write'], 'http://localhost:8080');
const appSpecifiedCoreNode = 'https://app-specified-core-node.local';
const userSession = new UserSession({ appConfig });
userSession.appConfig.coreNode = appSpecifiedCoreNode;
// userData is undefined in userSession so that userSession.appConfig.coreNode is used
const nameRecord = {
status: 'registered',
zonefile:
'$ORIGIN yukan.id\n$TTL 3600\n_http._tcp URI 10 1 "https://gaia.blockstack.org/hub/16zVUoP7f15nfTiHw2UNiX8NT5SWYqwNv3/0/profile.json"\n',
expire_block: 581432,
blockchain: 'bitcoin',
last_txid: 'f7fa811518566b1914a098c3bd61a810aee56390815bd608490b0860ac1b5b4d',
address: 'SP10VG75GE4PE0VBA3KD3NVKSYEMM3YV9V17HJ32N',
zonefile_hash: '98f42e11026d42d394b3424d4d7f0cccd6f376e2',
};
const nameRecordContent = JSON.stringify(nameRecord);

// const profileUrl = 'https://gaia.blockstack.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b3VudCIsInBsYWNlaG9sZGVyIjpmYWxzZSwic2VydmljZSI6ImdpdGh1YiIsImlkZW50aWZpZXIiOiJ5a25sIiwicHJvb2ZUeXBlIjoiaHR0cCIsInByb29mVXJsIjoiaHR0cHM6Ly9naXN0LmdpdGh1Yi5jb20veWtubC8xZjcwMThiOThmNzE2ZjAxNWE2Y2Y0NGZkYTA4MDZkNyJ9LHsiQHR5cGUiOiJBY2NvdW50IiwicGxhY2Vob2xkZXIiOmZhbHNlLCJzZXJ2aWNlIjoidHdpdHRlciIsImlkZW50aWZpZXIiOiJ5dWthbmwiLCJwcm9vZlR5cGUiOiJodHRwIiwicHJvb2ZVcmwiOiJodHRwczovL3R3aXR0ZXIuY29tL3l1a2FuTC9zdGF0dXMvOTE2NzQwNzQ5MjM2MTAxMTIwIn1dLCJuYW1lIjoiS2VuIExpYW8iLCJhcHBzIjp7Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MCI6Imh0dHBzOi8vZ2FpYS5ibG9ja3N0YWNrLm9yZy9odWIvMUREVXFmS3RRZ1lOdDcyMnd1QjRaMmZQQzdhaU5HUWE1Ui8ifX19.UyQNZ02kBFHEovbwiGaS-VQd57w9kcwn1Nt3QbW3afEMArg1OndmeplB7lzjMuRCLAi-88lkpQLkFw7LwKZ31Q',
'decodedToken': {
'header': {
'typ': 'JWT',
'alg': 'ES256K'
},
'payload': {
'jti': 'c48f9448-a0fe-4b9e-9d6a-fc0938c8e270',
'iat': '2018-01-08T18:22:24.796Z',
'exp': '2019-01-08T18:22:24.796Z',
'subject': {
'publicKey': '02487a91cd966faecee2aef3fde372809b46a36ee19248c01f72b645f44cef2e2c'
},
'issuer': {
'publicKey': '02487a91cd966faecee2aef3fde372809b46a36ee19248c01f72b645f44cef2e2c'
},
'claim': {
'@type': 'Person',
'@context': 'http://schema.org',
'image': [
{
'@type': 'ImageObject',
'name': 'avatar',
'contentUrl': 'https://www.dropbox.com/s/j1h0kts0m7aadip/avatar-0?dl=1'
}
],
'givenName': '',
'familyName': '',
'description': '',
'account': [
{
'@type': 'Account',
'placeholder': false,
'service': 'hackerNews',
'identifier': 'yukanl',
'proofType': 'http',
'proofUrl': 'https://news.ycombinator.com/user?id=yukanl'
},
{
'@type': 'Account',
'placeholder': false,
'service': 'github',
'identifier': 'yknl',
'proofType': 'http',
'proofUrl': 'https://gist.github.com/yknl/1f7018b98f716f015a6cf44fda0806d7'
},
{
'@type': 'Account',
'placeholder': false,
'service': 'twitter',
'identifier': 'yukanl',
'proofType': 'http',
'proofUrl': 'https://twitter.com/yukanL/status/916740749236101120'
}
],
'name': 'Ken Liao',
'apps': {
'http://localhost:8080': 'https://gaia.blockstack.org/hub/1DDUqfKtQgYNt722wuB4Z2fPC7aiNGQa5R/'
}
}
},
'signature': 'UyQNZ02kBFHEovbwiGaS-VQd57w9kcwn1Nt3QbW3afEMArg1OndmeplB7lzjMuRCLAi-88lkpQLkFw7LwKZ31Q'
}
}
]
/* eslint-enable */

// const fileUrl = 'https://gaia.blockstack.org/hub/1DDUqfKtQgYNt722wuB4Z2fPC7aiNGQa5R/file.json'
const fileContents = JSON.stringify({ key: 'value' });

const options = {
username: 'yukan.id',
app: 'http://localhost:8080',
decrypt: false,
};
fetchMock.once(nameRecordContent).once(JSON.stringify(profileContent)).once(fileContents);

const storage = new Storage({ userSession });

await storage.getFile(path, options).then(file => {
expect(file).toBeTruthy();
expect(JSON.parse(<string>file)).toEqual(JSON.parse(fileContents));
});
});

test('core node preferences respected for name lookups', async () => {
const path = 'file.json';
const gaiaHubConfig = {
Expand Down

1 comment on commit 144754b

@vercel
Copy link

@vercel vercel bot commented on 144754b Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.