mirror of
https://github.com/foss42/apidash.git
synced 2025-06-18 04:17:39 +08:00
Add request testing for Bad SSL endpoints
This commit is contained in:
@ -413,3 +413,15 @@ const httpRequestModelPost10Json = <String, dynamic>{
|
||||
{'name': 'imfile', 'value': '/Documents/up/1.png', 'type': 'file'}
|
||||
],
|
||||
};
|
||||
|
||||
/// Basic GET request model for apidash.dev
|
||||
const httpRequestModelGet13 = HttpRequestModel(
|
||||
method: HTTPVerb.get,
|
||||
url: 'https://apidash.dev',
|
||||
);
|
||||
|
||||
/// Basic GET request model for Certificate expired site
|
||||
const httpRequestModelGetBadSSL = HttpRequestModel(
|
||||
method: HTTPVerb.get,
|
||||
url: 'https://expired.badssl.com/',
|
||||
);
|
||||
|
@ -188,3 +188,15 @@ Map<String, dynamic> requestModelJson = {
|
||||
'message': null,
|
||||
'httpResponseModel': responseModelJson,
|
||||
};
|
||||
|
||||
/// Basic GET request model for apidash.dev
|
||||
const requestModelGet13 = RequestModel(
|
||||
id: 'get13',
|
||||
httpRequestModel: httpRequestModelGet13,
|
||||
);
|
||||
|
||||
/// Basic GET request model for badSSL
|
||||
const requestModelGetBadSSL = RequestModel(
|
||||
id: 'badSSL',
|
||||
httpRequestModel: httpRequestModelGetBadSSL,
|
||||
);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'http_response_models.dart';
|
||||
import 'request_models.dart';
|
||||
|
||||
void main() {
|
||||
test('Testing toJSON', () {
|
||||
@ -14,10 +14,14 @@ void main() {
|
||||
});
|
||||
|
||||
test('Testing fromResponse', () async {
|
||||
final response = await http.get(
|
||||
Uri.parse('https://api.apidash.dev/'),
|
||||
(HttpResponse?, Duration?, String?)? responseRec = await request(
|
||||
requestModelGet1.id,
|
||||
requestModelGet1.httpRequestModel!,
|
||||
defaultUriScheme: kDefaultUriScheme,
|
||||
noSSL: false,
|
||||
);
|
||||
final responseData = responseModel.fromResponse(response: response);
|
||||
|
||||
final responseData = responseModel.fromResponse(response: responseRec.$1!);
|
||||
expect(responseData.statusCode, 200);
|
||||
expect(responseData.body,
|
||||
'{"data":"Check out https://api.apidash.dev/docs to get started."}');
|
||||
@ -25,16 +29,48 @@ void main() {
|
||||
"data": "Check out https://api.apidash.dev/docs to get started."
|
||||
}''');
|
||||
});
|
||||
|
||||
test('Testing fromResponse for contentType not Json', () async {
|
||||
final response = await http.get(
|
||||
Uri.parse('https://apidash.dev/'),
|
||||
(HttpResponse?, Duration?, String?)? responseRec = await request(
|
||||
requestModelGet13.id,
|
||||
requestModelGet13.httpRequestModel!,
|
||||
defaultUriScheme: kDefaultUriScheme,
|
||||
noSSL: false,
|
||||
);
|
||||
final responseData = responseModel.fromResponse(response: response);
|
||||
|
||||
final responseData = responseModel.fromResponse(response: responseRec.$1!);
|
||||
expect(responseData.statusCode, 200);
|
||||
expect(responseData.body!.length, greaterThan(1000));
|
||||
expect(responseData.contentType, 'text/html; charset=utf-8');
|
||||
expect(responseData.mediaType!.mimeType, 'text/html');
|
||||
});
|
||||
|
||||
test('Testing fromResponse for Bad SSL with certificate check', () async {
|
||||
(HttpResponse?, Duration?, String?)? responseRec = await request(
|
||||
requestModelGetBadSSL.id,
|
||||
requestModelGetBadSSL.httpRequestModel!,
|
||||
defaultUriScheme: kDefaultUriScheme,
|
||||
noSSL: false,
|
||||
);
|
||||
expect(responseRec.$3?.contains("CERTIFICATE_VERIFY_FAILED"), true);
|
||||
expect(responseRec.$1, isNull);
|
||||
});
|
||||
|
||||
test('Testing fromResponse for Bad SSL with no certificate check', () async {
|
||||
(HttpResponse?, Duration?, String?)? responseRec = await request(
|
||||
requestModelGetBadSSL.id,
|
||||
requestModelGetBadSSL.httpRequestModel!,
|
||||
defaultUriScheme: kDefaultUriScheme,
|
||||
noSSL: true,
|
||||
);
|
||||
|
||||
final responseData = responseModel.fromResponse(response: responseRec.$1!);
|
||||
expect(responseData.statusCode, 200);
|
||||
expect(responseData.body!.length, greaterThan(400));
|
||||
expect(responseData.contentType, 'text/html');
|
||||
expect(responseData.mediaType!.mimeType, 'text/html');
|
||||
});
|
||||
|
||||
test('Testing hashcode', () {
|
||||
expect(responseModel.hashCode, greaterThan(0));
|
||||
});
|
||||
|
Reference in New Issue
Block a user