Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const assert = require('chai').assert
const { getRequestingWebId, verifyDelegator } = require('../lib/handlers/allow')
const rdf = require('rdflib')
const ns = require('solid-namespace')(rdf)
const alice = 'https://alice.com' // principal
const agentWebId = 'https://agent.example.com' // secretary
const verifiedSecretaryGraph = rdf.graph()
verifiedSecretaryGraph.add(
rdf.namedNode(alice),
ns.acl('delegates'),
rdf.namedNode(agentWebId)
)
const notVerifiedSecretaryGraph = rdf.graph()
describe('handlers/allow.js', () => {
describe('getRequestingWebId()', () => {
const emptyFetchDocument = () => {}
it('should return null if no webId and no onBehalfOf present', () => {
let webId // no secretary
let onBehalfOf // no principal
return getRequestingWebId(webId, onBehalfOf, emptyFetchDocument)
.then(userId => {
assert.equal(userId, null,
var errorHandler = require("debug")("rdflib-graph::error");
// Monkey Patching rdflib, Literals, BlankNodes and NamedNodes
var exLiteral = $rdf.literal("a", "de");
Object.defineProperty(Object.getPrototypeOf(exLiteral), "lex", { get: function () { return this.value } });
Object.getPrototypeOf(exLiteral).isBlankNode = function () { return false };
Object.getPrototypeOf(exLiteral).isLiteral = function () { return true };
Object.getPrototypeOf(exLiteral).isURI = function () { return false };
var exBlankNode = $rdf.blankNode();
Object.getPrototypeOf(exBlankNode).isBlankNode = function () { return true };
Object.getPrototypeOf(exBlankNode).isLiteral = function () { return false };
Object.getPrototypeOf(exBlankNode).isURI = function () { return false };
var exNamedNode = $rdf.namedNode("urn:x-dummy");
Object.getPrototypeOf(exNamedNode).isBlankNode = function () { return false };
Object.getPrototypeOf(exNamedNode).isLiteral = function () { return false };
Object.getPrototypeOf(exNamedNode).isURI = function () { return true };
var RDFLibGraph = function (store) {
this.store = store;
};
RDFLibGraph.prototype.find = function (s, p, o) {
return new RDFLibGraphIterator(this.store, s, p, o);
};
RDFLibGraph.prototype.query = function () {
return rdfquery(this);
export function saveUser (
webId: $rdf.NamedNode | string | null,
context?: AuthenticationContext
): $rdf.NamedNode | null {
// @@ TODO Remove the need for having context as output argument
let webIdUri: string
if (webId) {
webIdUri = (typeof webId === 'string') ? webId : webId.uri
const me = $rdf.namedNode(webIdUri)
if (context) {
context.me = me
}
return me
}
return null
}
kb.fetcher.nowOrWhenFetched(webId, (ok, err) => {
if (!ok) {
this.onGroupChanged(err)
return reject(err)
}
// make sure it's a valid person, group, or entity (for now just handle
// webId)
const webIdNode = rdf.namedNode(webId)
const rdfClass = kb.any(webIdNode, ns.rdf('type'))
if (!rdfClass || !rdfClass.equals(ns.foaf('Person'))) {
return reject(
new Error(
`Only people supported right now. (tried to add something of type ${
rdfClass.value
})`
)
)
}
return resolve(webIdNode)
})
}).then(webIdNode => {
it('parses and returns the agent mailto from the root acl', () => {
let userAccount = UserAccount.from({ username: 'alice' })
let rootAclGraph = rdf.graph()
rootAclGraph.add(
rdf.namedNode('https://alice.example.com/.acl#owner'),
ns.acl('agent'),
rdf.namedNode('mailto:alice@example.com')
)
let store = {
suffixAcl: '.acl',
getGraph: sinon.stub().resolves(rootAclGraph)
}
let options = { host, multiUser: true, store }
let accountManager = AccountManager.from(options)
return accountManager.loadAccountRecoveryEmail(userAccount)
.then(recoveryEmail => {
expect(recoveryEmail).to.equal('alice@example.com')
})
.then(graph => {
let webId = rdf.namedNode(certificate.webId)
let key = rdf.namedNode(certificate.keyUri)
expect(graph.anyStatementMatching(webId, ns.cert('key'), key))
.to.exist
expect(graph.anyStatementMatching(key, ns.rdf('type'), ns.cert('RSAPublicKey')))
.to.exist
expect(graph.anyStatementMatching(key, ns.cert('modulus')))
.to.exist
expect(graph.anyStatementMatching(key, ns.cert('exponent')))
.to.exist
})
}).timeout(3000)
.then(graph => {
let webId = rdf.namedNode(certificate.webId)
let key = rdf.namedNode(certificate.keyUri)
expect(graph.anyStatementMatching(webId, ns.cert('key'), key))
.to.exist
expect(graph.anyStatementMatching(key, ns.rdf('type'), ns.cert('RSAPublicKey')))
.to.exist
expect(graph.anyStatementMatching(key, ns.cert('modulus')))
.to.exist
expect(graph.anyStatementMatching(key, ns.cert('exponent')))
.to.exist
})
}).timeout(3000)
.then(graph => {
assert.ok(graph)
let fullname = $rdf.namedNode('http://example.org/stuff/1.0/fullname')
let match = graph.match(null, fullname)
assert.equal(match[0].object.value, 'Dave Beckett')
})
})
addCertKeyToGraph (certificate, graph) {
let webId = rdf.namedNode(certificate.webId)
let key = rdf.namedNode(certificate.keyUri)
let timeCreated = rdf.literal(certificate.date.toISOString(), ns.xsd('dateTime'))
let modulus = rdf.literal(certificate.modulus, ns.xsd('hexBinary'))
let exponent = rdf.literal(certificate.exponent, ns.xsd('int'))
let title = rdf.literal('Created by solid-server')
let label = rdf.literal(certificate.commonName)
graph.add(webId, ns.cert('key'), key)
graph.add(key, ns.rdf('type'), ns.cert('RSAPublicKey'))
graph.add(key, ns.dct('title'), title)
graph.add(key, ns.rdfs('label'), label)
graph.add(key, ns.dct('created'), timeCreated)
graph.add(key, ns.cert('modulus'), modulus)
graph.add(key, ns.cert('exponent'), exponent)
return graph
.then(response => {
let providerTerm = rdf.namedNode('http://www.w3.org/ns/solid/terms#oidcIssuer')
let providerUri = store.anyValue(rdf.namedNode(webId), providerTerm)
return providerUri
}, err => {
let error = new Error(`Could not reach Web ID ${webId} to discover provider`)