My work is cut out for me.
This commit is contained in:
parent
21f9181dc0
commit
dc9c39fc89
2 changed files with 18 additions and 4 deletions
|
@ -33,11 +33,14 @@ class Auth {
|
||||||
strategies.firstWhere((AuthStrategy x) => x.name == type);
|
strategies.firstWhere((AuthStrategy x) => x.name == type);
|
||||||
var result = await strategy.authenticate(
|
var result = await strategy.authenticate(
|
||||||
req, res, options: options ?? {});
|
req, res, options: options ?? {});
|
||||||
if (result is bool)
|
print("${req.path} -> $result");
|
||||||
|
if (result == true)
|
||||||
return result;
|
return result;
|
||||||
else {
|
else if(result != false) {
|
||||||
req.session['userId'] = await serializer(result);
|
req.session['userId'] = await serializer(result);
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
throw new AngelHttpException.NotAuthenticated();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ main() async {
|
||||||
Angel app;
|
Angel app;
|
||||||
http.Client client;
|
http.Client client;
|
||||||
String url;
|
String url;
|
||||||
|
String basicAuthUrl;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
client = new http.Client();
|
client = new http.Client();
|
||||||
|
@ -39,22 +40,26 @@ main() async {
|
||||||
app.get('/hello', 'Woo auth', middleware: [Auth.authenticate('local')]);
|
app.get('/hello', 'Woo auth', middleware: [Auth.authenticate('local')]);
|
||||||
app.post('/login', 'This should not be shown',
|
app.post('/login', 'This should not be shown',
|
||||||
middleware: [Auth.authenticate('local', localOpts)]);
|
middleware: [Auth.authenticate('local', localOpts)]);
|
||||||
app.get('/success', "yep", middleware: []);
|
app.get('/success', "yep", middleware: ['auth']);
|
||||||
app.get('/failure', "nope");
|
app.get('/failure', "nope");
|
||||||
|
|
||||||
HttpServer server = await app.startServer(
|
HttpServer server = await app.startServer(
|
||||||
InternetAddress.LOOPBACK_IP_V4, 0);
|
InternetAddress.LOOPBACK_IP_V4, 0);
|
||||||
url = "http://${server.address.host}:${server.port}";
|
url = "http://${server.address.host}:${server.port}";
|
||||||
|
basicAuthUrl =
|
||||||
|
"http://username:password@${server.address.host}:${server.port}";
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
await app.httpServer.close(force: true);
|
await app.httpServer.close(force: true);
|
||||||
client = null;
|
client = null;
|
||||||
url = null;
|
url = null;
|
||||||
|
basicAuthUrl = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can use login as middleware', () async {
|
test('can use login as middleware', () async {
|
||||||
var response = await client.get("$url/success");
|
var response = await client.get("$url/success", headers: {'Accept': 'application/json'});
|
||||||
|
print(response.body);
|
||||||
expect(response.statusCode, equals(401));
|
expect(response.statusCode, equals(401));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -90,6 +95,12 @@ main() async {
|
||||||
expect(response.body, equals('"Woo auth"'));
|
expect(response.body, equals('"Woo auth"'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('allow basic via URL encoding', () async {
|
||||||
|
var response = await client.get(
|
||||||
|
basicAuthUrl, headers: headers);
|
||||||
|
expect(response.body, equals('"Woo auth"'));
|
||||||
|
});
|
||||||
|
|
||||||
test('force basic', () async {
|
test('force basic', () async {
|
||||||
Auth.strategies.clear();
|
Auth.strategies.clear();
|
||||||
Auth.strategies.add(new LocalAuthStrategy(
|
Auth.strategies.add(new LocalAuthStrategy(
|
||||||
|
|
Loading…
Reference in a new issue