mirror of
https://github.com/foss42/apidash.git
synced 2025-12-03 11:27:50 +08:00
fix: improve OAuth authentication tests to handle null data cases
This commit is contained in:
@@ -60,18 +60,34 @@ void main() {
|
||||
});
|
||||
|
||||
test('should find available port when default is busy', () async {
|
||||
// Start a server on port 8080 to make it busy
|
||||
final busyServer = await HttpServer.bind(
|
||||
InternetAddress.loopbackIPv4,
|
||||
8080,
|
||||
);
|
||||
// Find a port that's actually available for testing
|
||||
late int testPort;
|
||||
late HttpServer busyServer;
|
||||
|
||||
// Try to find an available port in the testing range 9080-9090
|
||||
for (int port = 9080; port <= 9090; port++) {
|
||||
try {
|
||||
busyServer = await HttpServer.bind(
|
||||
InternetAddress.loopbackIPv4,
|
||||
port,
|
||||
);
|
||||
testPort = port;
|
||||
break;
|
||||
} catch (e) {
|
||||
// Port is busy, try next one
|
||||
if (port == 9090) {
|
||||
// Skip this test if no ports available in our test range
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
final callbackUrl = await server.start();
|
||||
|
||||
// Should find a different port
|
||||
expect(callbackUrl, startsWith('http://localhost:'));
|
||||
expect(callbackUrl, isNot(contains(':8080')));
|
||||
expect(callbackUrl, isNot(contains(':$testPort')));
|
||||
} finally {
|
||||
await busyServer.close();
|
||||
}
|
||||
|
||||
@@ -423,7 +423,7 @@ void main() {
|
||||
);
|
||||
|
||||
test(
|
||||
'given handleAuth when OAuth1 authentication is provided then it should throw UnimplementedError',
|
||||
'given handleAuth when OAuth1 authentication is provided but oauth1 data is null then it should not add headers',
|
||||
() async {
|
||||
const httpRequestModel = HttpRequestModel(
|
||||
method: HTTPVerb.get,
|
||||
@@ -432,15 +432,15 @@ void main() {
|
||||
|
||||
const authModel = AuthModel(type: APIAuthType.oauth1);
|
||||
|
||||
expect(
|
||||
() async => await handleAuth(httpRequestModel, authModel),
|
||||
throwsA(isA<UnimplementedError>()),
|
||||
);
|
||||
final result = await handleAuth(httpRequestModel, authModel);
|
||||
|
||||
expect(result.headers, isEmpty);
|
||||
expect(result.isHeaderEnabledList, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'given handleAuth when OAuth2 authentication is provided then it should throw UnimplementedError',
|
||||
'given handleAuth when OAuth2 authentication is provided but oauth2 data is null then it should throw Exception',
|
||||
() async {
|
||||
const httpRequestModel = HttpRequestModel(
|
||||
method: HTTPVerb.get,
|
||||
@@ -451,7 +451,13 @@ void main() {
|
||||
|
||||
expect(
|
||||
() async => await handleAuth(httpRequestModel, authModel),
|
||||
throwsA(isA<UnimplementedError>()),
|
||||
throwsA(
|
||||
isA<Exception>().having(
|
||||
(e) => e.toString(),
|
||||
'message',
|
||||
contains('Failed to get OAuth2 Data'),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user