Skip to content

Commit f9096b5

Browse files
author
nicola
committed
implemented and tested forceUser, fix #157
1 parent 3d809ec commit f9096b5

6 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎bin/ldnode.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ var argv = require('nomnom')
5353
help: 'HTTP Session secret key (e.g. "your secret phrase")',
5454
abbr: 's'
5555
})
56+
.option('forceUser', {
57+
help: 'Force a WebID to always be logged in (usefull when offline)',
58+
abbr: 'fU',
59+
full: 'force-user'
60+
})
5661
.option('proxy', {
5762
full: 'proxy',
5863
help: 'Use a proxy on example.tld/proxyPath',

‎lib/ldp.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function LDP(argv) {
1919
argv = argv || {};
2020
var ldp = this;
2121
// From input
22+
ldp.forceUser = argv.forceUser;
2223
ldp.cache = argv.cache;
2324
ldp.live = argv.live;
2425
ldp.root = argv.root || process.cwd();

‎lib/login.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ var HttpError = require('./http-error');
77
function loginHandler(req, res, next) {
88
var ldp = req.app.locals.ldp;
99

10+
if (ldp.forceUser) {
11+
req.session.userId = ldp.forceUser;
12+
req.session.identified = true;
13+
debug("Identified user: " + req.session.userId);
14+
res.set('User', req.session.userId);
15+
return next();
16+
}
17+
1018
// No webid required? skip
1119
if (!ldp.webid) {
1220
setEmptySession(req);

‎test/params.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,34 @@ describe('LDNODE params', function () {
179179
});
180180
});
181181
});
182+
183+
describe('forcedUser', function () {
184+
185+
var ldpHttpsServer
186+
var ldp = ldnode.createServer({
187+
forceUser: 'https://fakeaccount.com/profile#me',
188+
root: __dirname + '/resources/acl/fake-account',
189+
key: __dirname + '/keys/key.pem',
190+
cert: __dirname + '/keys/cert.pem',
191+
webid: true,
192+
host: 'localhost:3457'
193+
})
194+
195+
var ldpHttpsServer
196+
before(function (done) {
197+
ldpHttpsServer = ldp.listen(3459, done)
198+
})
199+
200+
after(function () {
201+
if (ldpHttpsServer) ldpHttpsServer.close()
202+
})
203+
204+
var server = supertest('https://localhost:3459')
205+
206+
it ('should find resource in correct path', function (done) {
207+
server.get('/hello.html')
208+
.expect('User', 'https://fakeaccount.com/profile#me')
209+
.end(done);
210+
});
211+
});
182212
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<#0>
2+
<http://www.w3.org/ns/auth/acl#defaultForNew> <./> ;
3+
<http://www.w3.org/ns/auth/acl#agent> <https://fakeaccount.com/profile#me> ;
4+
<http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>, <http://www.w3.org/ns/auth/acl#Control>.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Hello</title>
5+
</head>
6+
<body>
7+
Hello
8+
</body>
9+
</html>

0 commit comments

Comments
 (0)