Fixed auth failed test cases
This commit is contained in:
parent
8e251e553a
commit
a806d7c6db
3 changed files with 24 additions and 8 deletions
|
@ -1,12 +1,17 @@
|
|||
### Load landing page
|
||||
GET http://localhost:3000/ HTTP/1.1
|
||||
|
||||
### Success redirect
|
||||
### login (call_back)
|
||||
POST http://localhost:3000/login HTTP/1.1
|
||||
Content-Type: application/json
|
||||
Authorization: Basic jdoe1:password
|
||||
|
||||
### Failure redirect
|
||||
### Success redirect (local)
|
||||
POST http://localhost:3000/login HTTP/1.1
|
||||
Content-Type: application/json
|
||||
Authorization: Basic username:password
|
||||
|
||||
### Failure redirect (local)
|
||||
POST http://localhost:3000/login HTTP/1.1
|
||||
Content-Type: application/json
|
||||
Authorization: Basic password:username
|
||||
|
|
|
@ -25,10 +25,14 @@ Future<Map<String, String>> verifier(String? username, String? password) async {
|
|||
|
||||
Future wireAuth(Angel app) async {
|
||||
//auth.strategies['local'] = LocalAuthStrategy(verifier);
|
||||
auth.strategies['local'] = LocalAuthStrategy(verifier, forceBasic: true, realm: 'test');
|
||||
auth.strategies['local'] =
|
||||
LocalAuthStrategy(verifier, forceBasic: true, realm: 'test');
|
||||
await app.configure(auth.configureServer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Backend for local test cases
|
||||
*/
|
||||
void main() async {
|
||||
Angel app = Angel(reflector: MirrorsReflector());
|
||||
AngelHttp angelHttp = AngelHttp(app, useZone: false);
|
||||
|
|
|
@ -81,15 +81,22 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
|
|||
}
|
||||
}
|
||||
|
||||
// User authentication succeeded
|
||||
if (verificationResult == true ||
|
||||
(verificationResult is Map && verificationResult.isNotEmpty)) {
|
||||
return verificationResult;
|
||||
// User authentication succeeded can return Map(one element), User(non null) or true
|
||||
if (verificationResult != null && verificationResult != false) {
|
||||
if (verificationResult is Map && verificationResult.isNotEmpty) {
|
||||
return verificationResult;
|
||||
} else if (verificationResult is! Map) {
|
||||
return verificationResult;
|
||||
}
|
||||
}
|
||||
|
||||
// Force basic if set
|
||||
if (forceBasic) {
|
||||
res.headers['www-authenticate'] = 'Basic realm="$realm"';
|
||||
//res.headers['www-authenticate'] = 'Basic realm="$realm"';
|
||||
res
|
||||
..statusCode = 401
|
||||
..headers['www-authenticate'] = 'Basic realm="$realm"';
|
||||
await res.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue