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 {
|
test('should find available port when default is busy', () async {
|
||||||
// Start a server on port 8080 to make it busy
|
// Find a port that's actually available for testing
|
||||||
final busyServer = await HttpServer.bind(
|
late int testPort;
|
||||||
InternetAddress.loopbackIPv4,
|
late HttpServer busyServer;
|
||||||
8080,
|
|
||||||
);
|
// 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 {
|
try {
|
||||||
final callbackUrl = await server.start();
|
final callbackUrl = await server.start();
|
||||||
|
|
||||||
// Should find a different port
|
// Should find a different port
|
||||||
expect(callbackUrl, startsWith('http://localhost:'));
|
expect(callbackUrl, startsWith('http://localhost:'));
|
||||||
expect(callbackUrl, isNot(contains(':8080')));
|
expect(callbackUrl, isNot(contains(':$testPort')));
|
||||||
} finally {
|
} finally {
|
||||||
await busyServer.close();
|
await busyServer.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -423,7 +423,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
test(
|
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 {
|
() async {
|
||||||
const httpRequestModel = HttpRequestModel(
|
const httpRequestModel = HttpRequestModel(
|
||||||
method: HTTPVerb.get,
|
method: HTTPVerb.get,
|
||||||
@@ -432,15 +432,15 @@ void main() {
|
|||||||
|
|
||||||
const authModel = AuthModel(type: APIAuthType.oauth1);
|
const authModel = AuthModel(type: APIAuthType.oauth1);
|
||||||
|
|
||||||
expect(
|
final result = await handleAuth(httpRequestModel, authModel);
|
||||||
() async => await handleAuth(httpRequestModel, authModel),
|
|
||||||
throwsA(isA<UnimplementedError>()),
|
expect(result.headers, isEmpty);
|
||||||
);
|
expect(result.isHeaderEnabledList, isEmpty);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
test(
|
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 {
|
() async {
|
||||||
const httpRequestModel = HttpRequestModel(
|
const httpRequestModel = HttpRequestModel(
|
||||||
method: HTTPVerb.get,
|
method: HTTPVerb.get,
|
||||||
@@ -451,7 +451,13 @@ void main() {
|
|||||||
|
|
||||||
expect(
|
expect(
|
||||||
() async => await handleAuth(httpRequestModel, authModel),
|
() 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