Fixed auth failed test cases

This commit is contained in:
thomashii 2023-06-05 19:00:42 +08:00
parent 8e251e553a
commit a806d7c6db
3 changed files with 24 additions and 8 deletions

View file

@ -1,12 +1,17 @@
### Load landing page ### Load landing page
GET http://localhost:3000/ HTTP/1.1 GET http://localhost:3000/ HTTP/1.1
### Success redirect ### login (call_back)
POST http://localhost:3000/login HTTP/1.1 POST http://localhost:3000/login HTTP/1.1
Content-Type: application/json Content-Type: application/json
Authorization: Basic jdoe1:password 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 POST http://localhost:3000/login HTTP/1.1
Content-Type: application/json Content-Type: application/json
Authorization: Basic password:username Authorization: Basic password:username

View file

@ -25,10 +25,14 @@ Future<Map<String, String>> verifier(String? username, String? password) async {
Future wireAuth(Angel app) async { Future wireAuth(Angel app) async {
//auth.strategies['local'] = LocalAuthStrategy(verifier); //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); await app.configure(auth.configureServer);
} }
/*
* Backend for local test cases
*/
void main() async { void main() async {
Angel app = Angel(reflector: MirrorsReflector()); Angel app = Angel(reflector: MirrorsReflector());
AngelHttp angelHttp = AngelHttp(app, useZone: false); AngelHttp angelHttp = AngelHttp(app, useZone: false);

View file

@ -81,15 +81,22 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
} }
} }
// User authentication succeeded // User authentication succeeded can return Map(one element), User(non null) or true
if (verificationResult == true || if (verificationResult != null && verificationResult != false) {
(verificationResult is Map && verificationResult.isNotEmpty)) { if (verificationResult is Map && verificationResult.isNotEmpty) {
return verificationResult; return verificationResult;
} else if (verificationResult is! Map) {
return verificationResult;
}
} }
// Force basic if set // Force basic if set
if (forceBasic) { 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; return null;
} }