Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Merge 03c2ddc into b17d76a
Browse files Browse the repository at this point in the history
  • Loading branch information
bochaco committed Dec 7, 2018
2 parents b17d76a + 03c2ddc commit f905080
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/api/emulations/rdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ class RDF {
}, Promise.resolve([]));

const entriesGraphs = await Promise.all(validGraphs);

if (!id) {
// This simply means that none of the existing entries are RDF graphs.
// We throw the error and it's up to the caller to decide
// what to do in such an scenario
throw makeError(errConst.MISSING_RDF_ID.code, errConst.MISSING_RDF_ID.msg);
}

Expand Down
19 changes: 11 additions & 8 deletions src/api/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ class WebInterface {

const publicNamesContainer = await app.auth.getContainer(PUBLIC_NAMES_CONTAINER);
const publicNamesRdf = publicNamesContainer.emulateAs('rdf');
const toDecrypt = true;
await publicNamesRdf.nowOrWhenFetched(null, toDecrypt);

// Here we do basic container setup for RDF entries.
// Doesn't matter if already existing, will just write same entries.
Expand All @@ -110,6 +108,15 @@ class WebInterface {
const newResourceName = publicNamesRdf.sym(`${graphName}#${publicName}`);

publicNamesRdf.setId(graphName);
try {
const toDecrypt = true;
await publicNamesRdf.nowOrWhenFetched(null, toDecrypt);
} catch (e) {
// ignore no ID set in case nothing has been added yet
if (e.code !== errConst.MISSING_RDF_ID.code) {
throw new Error({ code: e.code, message: e.message });
}
}

const vocabs = this.getVocabs(publicNamesRdf);
publicNamesRdf.add(id, vocabs.RDFS('type'), vocabs.LDP('DirectContainer'));
Expand Down Expand Up @@ -247,21 +254,17 @@ class WebInterface {
const id = directoryRDF.sym(graphName);
directoryRDF.setId(graphName);

let existingRDF = false;
try {
await directoryRDF.nowOrWhenFetched();
existingRDF = true;
} catch (e) {
// ignore no ID set in case nothing has been added yet
if (e.code !== errConst.MISSING_RDF_ID.code) {
throw new Error({ code: e.code, message: e.message });
}
}

if (!existingRDF) {
directoryRDF.add(id, vocabs.DCTERMS('title'), directoryRDF.literal(`${PUBLIC_CONTAINER} default container`));
directoryRDF.add(id, vocabs.DCTERMS('description'), directoryRDF.literal('Container to keep track of public data for the account'));
}
directoryRDF.add(id, vocabs.DCTERMS('title'), directoryRDF.literal(`${PUBLIC_CONTAINER} default container`));
directoryRDF.add(id, vocabs.DCTERMS('description'), directoryRDF.literal('Container to keep track of public data for the account'));

const hostname = parseUrl(webIdUri).hostname;
const newResourceName = directoryRDF.sym(`${graphName}/${hostname}`);
Expand Down
25 changes: 18 additions & 7 deletions test/experimental_apis/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ describe('Experimental Web API', () => {
return should(publicNames).containDeep(['safe://_publicNames#thisIsATestDomain']);
});

it('should add publicName even on top of container old data format', async () => {
const newAuthedApp = await h.publicNamesTestApp();
const pubNamesCont = await newAuthedApp.auth.getContainer('_publicNames');
const mut = await newAuthedApp.mutableData.newMutation();
const encKey = await pubNamesCont.encryptKey('key');
const encValue = await pubNamesCont.encryptValue('value');
await mut.insert(encKey, encValue);
await pubNamesCont.applyEntriesMutation(mut);
await newAuthedApp.web.addPublicNameToDirectory('thisIsATestDomain', fakeSubdomainRDF);
const publicNames = await newAuthedApp.web.getPublicNames();
should(publicNames).be.a.Array();
return should(publicNames).containDeep(['safe://_publicNames#thisIsATestDomain']);
});

it('should create two publicNames', async () => {
await authedApp.web.addPublicNameToDirectory('thisIsATestDomain', fakeSubdomainRDF);
await authedApp.web.addPublicNameToDirectory('thisIsASecondTestDomain', fakeSubdomainRDF);
Expand Down Expand Up @@ -355,18 +369,15 @@ describe('Experimental Web API', () => {
const entries = await directory.getEntries();
const entriesList = await entries.listEntries();

// TODO: Encrypt/Decrypting.
const webIds = await entriesList.map((entry) => {
const webIds = await entriesList.reduce((ids, entry) => {
const key = entry.key.toString();
const value = entry.value.buf.toString();
const theId = {};
if (key.includes('/webId/') && value.length) {
theId[key] = value;
ids.push({ [key]: value });
}
return theId;
});
return ids;
}, []);

// TODO: We cannot get from the RDF a specific title AND it's xorName :|
should(webIds).be.a.Array();
should(webIds.length).be.equal(2);
const jsonString = JSON.stringify(webIds);
Expand Down

0 comments on commit f905080

Please sign in to comment.