My work is cut out for me.

This commit is contained in:
regiostech 2016-05-03 19:43:41 -04:00
parent 21f9181dc0
commit dc9c39fc89
2 changed files with 18 additions and 4 deletions

View file

@ -33,11 +33,14 @@ class Auth {
strategies.firstWhere((AuthStrategy x) => x.name == type);
var result = await strategy.authenticate(
req, res, options: options ?? {});
if (result is bool)
print("${req.path} -> $result");
if (result == true)
return result;
else {
else if(result != false) {
req.session['userId'] = await serializer(result);
return true;
} else {
throw new AngelHttpException.NotAuthenticated();
}
};
}

View file

@ -30,6 +30,7 @@ main() async {
Angel app;
http.Client client;
String url;
String basicAuthUrl;
setUp(() async {
client = new http.Client();
@ -39,22 +40,26 @@ main() async {
app.get('/hello', 'Woo auth', middleware: [Auth.authenticate('local')]);
app.post('/login', 'This should not be shown',
middleware: [Auth.authenticate('local', localOpts)]);
app.get('/success', "yep", middleware: []);
app.get('/success', "yep", middleware: ['auth']);
app.get('/failure', "nope");
HttpServer server = await app.startServer(
InternetAddress.LOOPBACK_IP_V4, 0);
url = "http://${server.address.host}:${server.port}";
basicAuthUrl =
"http://username:password@${server.address.host}:${server.port}";
});
tearDown(() async {
await app.httpServer.close(force: true);
client = null;
url = null;
basicAuthUrl = null;
});
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));
});
@ -90,6 +95,12 @@ main() async {
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 {
Auth.strategies.clear();
Auth.strategies.add(new LocalAuthStrategy(