mirror of
https://github.com/foss42/apidash.git
synced 2025-06-12 16:38:18 +08:00
Merge pull request #504 from WrathOP/add-feature-parsing-form-data
Implemented FormData parsing in curl_parser and added tests for it.
This commit is contained in:
packages/curl_parser
@ -1,3 +1,7 @@
|
|||||||
|
## 0.1.1
|
||||||
|
|
||||||
|
- Add formdata support and new test cases.
|
||||||
|
|
||||||
## 0.1.0
|
## 0.1.0
|
||||||
|
|
||||||
- Added new test cases.
|
- Added new test cases.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
import 'package:apidash_core/apidash_core.dart';
|
||||||
import 'package:args/args.dart';
|
import 'package:args/args.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import '../../utils/string.dart';
|
import '../utils/string.dart';
|
||||||
|
|
||||||
/// A representation of a cURL command in Dart.
|
/// A representation of a cURL command in Dart.
|
||||||
///
|
///
|
||||||
@ -10,7 +11,7 @@ class Curl extends Equatable {
|
|||||||
/// Specifies the HTTP request method (e.g., GET, POST, PUT, DELETE).
|
/// Specifies the HTTP request method (e.g., GET, POST, PUT, DELETE).
|
||||||
final String method;
|
final String method;
|
||||||
|
|
||||||
/// Specifies the HTTP request URL
|
/// Specifies the HTTP request URL.
|
||||||
final Uri uri;
|
final Uri uri;
|
||||||
|
|
||||||
/// Adds custom HTTP headers to the request.
|
/// Adds custom HTTP headers to the request.
|
||||||
@ -34,6 +35,9 @@ class Curl extends Equatable {
|
|||||||
/// Sends data as a multipart/form-data request.
|
/// Sends data as a multipart/form-data request.
|
||||||
final bool form;
|
final bool form;
|
||||||
|
|
||||||
|
/// Form data list.
|
||||||
|
final List<FormDataModel>? formData;
|
||||||
|
|
||||||
/// Allows insecure SSL connections.
|
/// Allows insecure SSL connections.
|
||||||
final bool insecure;
|
final bool insecure;
|
||||||
|
|
||||||
@ -42,7 +46,7 @@ class Curl extends Equatable {
|
|||||||
|
|
||||||
/// Constructs a new Curl object with the specified parameters.
|
/// Constructs a new Curl object with the specified parameters.
|
||||||
///
|
///
|
||||||
/// The uri parameter is required, while the remaining parameters are optional.
|
/// The `uri` parameter is required, while the remaining parameters are optional.
|
||||||
Curl({
|
Curl({
|
||||||
required this.uri,
|
required this.uri,
|
||||||
this.method = 'GET',
|
this.method = 'GET',
|
||||||
@ -52,12 +56,18 @@ class Curl extends Equatable {
|
|||||||
this.user,
|
this.user,
|
||||||
this.referer,
|
this.referer,
|
||||||
this.userAgent,
|
this.userAgent,
|
||||||
|
this.formData,
|
||||||
this.form = false,
|
this.form = false,
|
||||||
this.insecure = false,
|
this.insecure = false,
|
||||||
this.location = false,
|
this.location = false,
|
||||||
});
|
}) {
|
||||||
|
assert(
|
||||||
|
['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS'].contains(method));
|
||||||
|
assert(['http', 'https'].contains(uri.scheme));
|
||||||
|
assert(form ? formData != null : formData == null);
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse [curlString] as a [Curl] class instance.
|
/// Parses [curlString] into a [Curl] class instance.
|
||||||
///
|
///
|
||||||
/// Like [parse] except that this function returns `null` where a
|
/// Like [parse] except that this function returns `null` where a
|
||||||
/// similar call to [parse] would throw a throwable.
|
/// similar call to [parse] would throw a throwable.
|
||||||
@ -70,8 +80,9 @@ class Curl extends Equatable {
|
|||||||
static Curl? tryParse(String curlString) {
|
static Curl? tryParse(String curlString) {
|
||||||
try {
|
try {
|
||||||
return Curl.parse(curlString);
|
return Curl.parse(curlString);
|
||||||
} catch (_) {}
|
} catch (_) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse [curlString] as a [Curl] class instance.
|
/// Parse [curlString] as a [Curl] class instance.
|
||||||
@ -82,12 +93,10 @@ class Curl extends Equatable {
|
|||||||
/// print(Curl.parse('1f')); // [Exception] is thrown
|
/// print(Curl.parse('1f')); // [Exception] is thrown
|
||||||
/// ```
|
/// ```
|
||||||
static Curl parse(String curlString) {
|
static Curl parse(String curlString) {
|
||||||
String? clean(String? url) {
|
|
||||||
return url?.replaceAll('"', '').replaceAll("'", '');
|
|
||||||
}
|
|
||||||
|
|
||||||
final parser = ArgParser(allowTrailingOptions: true);
|
final parser = ArgParser(allowTrailingOptions: true);
|
||||||
|
|
||||||
|
// TODO: Add more options
|
||||||
|
// https://gist.github.com/eneko/dc2d8edd9a4b25c5b0725dd123f98b10
|
||||||
// Define the expected options
|
// Define the expected options
|
||||||
parser.addOption('url');
|
parser.addOption('url');
|
||||||
parser.addOption('request', abbr: 'X');
|
parser.addOption('request', abbr: 'X');
|
||||||
@ -98,7 +107,7 @@ class Curl extends Equatable {
|
|||||||
parser.addOption('referer', abbr: 'e');
|
parser.addOption('referer', abbr: 'e');
|
||||||
parser.addOption('user-agent', abbr: 'A');
|
parser.addOption('user-agent', abbr: 'A');
|
||||||
parser.addFlag('head', abbr: 'I');
|
parser.addFlag('head', abbr: 'I');
|
||||||
parser.addFlag('form', abbr: 'F');
|
parser.addMultiOption('form', abbr: 'F');
|
||||||
parser.addFlag('insecure', abbr: 'k');
|
parser.addFlag('insecure', abbr: 'k');
|
||||||
parser.addFlag('location', abbr: 'L');
|
parser.addFlag('location', abbr: 'L');
|
||||||
|
|
||||||
@ -111,8 +120,6 @@ class Curl extends Equatable {
|
|||||||
|
|
||||||
final result = parser.parse(splittedCurlString);
|
final result = parser.parse(splittedCurlString);
|
||||||
|
|
||||||
final method = (result['request'] as String?)?.toUpperCase();
|
|
||||||
|
|
||||||
// Extract the request headers
|
// Extract the request headers
|
||||||
Map<String, String>? headers;
|
Map<String, String>? headers;
|
||||||
if (result['header'] != null) {
|
if (result['header'] != null) {
|
||||||
@ -129,26 +136,59 @@ class Curl extends Equatable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String? url = clean(result['url']);
|
// Parse form data
|
||||||
|
List<FormDataModel>? formData;
|
||||||
|
if (result['form'] is List<String> &&
|
||||||
|
(result['form'] as List<String>).isNotEmpty) {
|
||||||
|
formData = <FormDataModel>[];
|
||||||
|
for (final formEntry in result['form']) {
|
||||||
|
final pairs = formEntry.split('=');
|
||||||
|
if (pairs.length != 2) {
|
||||||
|
throw Exception(
|
||||||
|
'Form data entry $formEntry is not in key=value format');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handling the file or text type
|
||||||
|
var formDataModel = pairs[1].startsWith('@')
|
||||||
|
? FormDataModel(
|
||||||
|
name: pairs[0],
|
||||||
|
value: pairs[1].substring(1),
|
||||||
|
type: FormDataType.file,
|
||||||
|
)
|
||||||
|
: FormDataModel(
|
||||||
|
name: pairs[0],
|
||||||
|
value: pairs[1],
|
||||||
|
type: FormDataType.text,
|
||||||
|
);
|
||||||
|
|
||||||
|
formData.add(formDataModel);
|
||||||
|
}
|
||||||
|
headers ??= <String, String>{};
|
||||||
|
headers[kHeaderContentType] = ContentType.formdata.header;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle URL and query parameters
|
||||||
|
final url = clean(result['url']) ?? clean(result.rest.firstOrNull);
|
||||||
|
if (url == null) {
|
||||||
|
throw Exception('URL is null');
|
||||||
|
}
|
||||||
|
final uri = Uri.parse(url);
|
||||||
|
|
||||||
|
final method = result['head']
|
||||||
|
? 'HEAD'
|
||||||
|
: ((result['request'] as String?)?.toUpperCase() ?? 'GET');
|
||||||
final String? data = result['data'];
|
final String? data = result['data'];
|
||||||
final String? cookie = result['cookie'];
|
final String? cookie = result['cookie'];
|
||||||
final String? user = result['user'];
|
final String? user = result['user'];
|
||||||
final String? referer = result['referer'];
|
final String? referer = result['referer'];
|
||||||
final String? userAgent = result['user-agent'];
|
final String? userAgent = result['user-agent'];
|
||||||
final bool form = result['form'] ?? false;
|
final bool form = formData != null && formData.isNotEmpty;
|
||||||
final bool head = result['head'] ?? false;
|
|
||||||
final bool insecure = result['insecure'] ?? false;
|
final bool insecure = result['insecure'] ?? false;
|
||||||
final bool location = result['location'] ?? false;
|
final bool location = result['location'] ?? false;
|
||||||
|
|
||||||
// Extract the request URL
|
// Extract the request URL
|
||||||
url ??= result.rest.isNotEmpty ? clean(result.rest.first) : null;
|
|
||||||
if (url == null) {
|
|
||||||
throw Exception('url is null');
|
|
||||||
}
|
|
||||||
final uri = Uri.parse(url);
|
|
||||||
|
|
||||||
return Curl(
|
return Curl(
|
||||||
method: head ? "HEAD" : (method ?? 'GET'),
|
method: method,
|
||||||
uri: uri,
|
uri: uri,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
data: data,
|
data: data,
|
||||||
@ -157,12 +197,13 @@ class Curl extends Equatable {
|
|||||||
referer: referer,
|
referer: referer,
|
||||||
userAgent: userAgent,
|
userAgent: userAgent,
|
||||||
form: form,
|
form: form,
|
||||||
|
formData: formData,
|
||||||
insecure: insecure,
|
insecure: insecure,
|
||||||
location: location,
|
location: location,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Formatted cURL command
|
/// Converts the Curl object to a formatted cURL command string.
|
||||||
String toCurlString() {
|
String toCurlString() {
|
||||||
var cmd = 'curl ';
|
var cmd = 'curl ';
|
||||||
|
|
||||||
@ -176,7 +217,6 @@ class Curl extends Equatable {
|
|||||||
|
|
||||||
// Add the URL
|
// Add the URL
|
||||||
cmd += '"${Uri.encodeFull(uri.toString())}" ';
|
cmd += '"${Uri.encodeFull(uri.toString())}" ';
|
||||||
|
|
||||||
// Add the headers
|
// Add the headers
|
||||||
headers?.forEach((key, value) {
|
headers?.forEach((key, value) {
|
||||||
cmd += '\\\n -H "$key: $value" ';
|
cmd += '\\\n -H "$key: $value" ';
|
||||||
@ -204,15 +244,22 @@ class Curl extends Equatable {
|
|||||||
}
|
}
|
||||||
// Add the form flag
|
// Add the form flag
|
||||||
if (form) {
|
if (form) {
|
||||||
cmd += " \\\n -F ";
|
for (final formEntry in formData!) {
|
||||||
|
cmd += "\\\n -F ";
|
||||||
|
if (formEntry.type == FormDataType.file) {
|
||||||
|
cmd += '"${formEntry.name}=@${formEntry.value}" ';
|
||||||
|
} else {
|
||||||
|
cmd += '"${formEntry.name}=${formEntry.value}" ';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Add the insecure flag
|
// Add the insecure flag
|
||||||
if (insecure) {
|
if (insecure) {
|
||||||
cmd += " \\\n -k ";
|
cmd += "-k ";
|
||||||
}
|
}
|
||||||
// Add the location flag
|
// Add the location flag
|
||||||
if (location) {
|
if (location) {
|
||||||
cmd += " \\\n -L ";
|
cmd += "-L ";
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd.trim();
|
return cmd.trim();
|
||||||
@ -229,6 +276,7 @@ class Curl extends Equatable {
|
|||||||
referer,
|
referer,
|
||||||
userAgent,
|
userAgent,
|
||||||
form,
|
form,
|
||||||
|
formData,
|
||||||
insecure,
|
insecure,
|
||||||
location,
|
location,
|
||||||
];
|
];
|
||||||
|
@ -3,3 +3,7 @@ import 'package:shlex/shlex.dart' as shlex;
|
|||||||
List<String> splitAsCommandLineArgs(String command) {
|
List<String> splitAsCommandLineArgs(String command) {
|
||||||
return shlex.split(command);
|
return shlex.split(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String? clean(String? url) {
|
||||||
|
return url?.replaceAll('"', '').replaceAll("'", '');
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: curl_parser
|
name: curl_parser
|
||||||
description: Parse cURL command to Dart object and convert Dart object to cURL command.
|
description: Parse cURL command to Dart object and convert Dart object to cURL command.
|
||||||
version: 0.1.0
|
version: 0.1.1
|
||||||
homepage: https://github.com/foss42/apidash/tree/main/packages/curl_parser
|
homepage: https://github.com/foss42/apidash/tree/main/packages/curl_parser
|
||||||
repository: https://github.com/foss42/apidash/tree/main/packages/curl_parser
|
repository: https://github.com/foss42/apidash/tree/main/packages/curl_parser
|
||||||
issue_tracker: https://github.com/foss42/apidash/issues
|
issue_tracker: https://github.com/foss42/apidash/issues
|
||||||
@ -20,6 +20,8 @@ dependencies:
|
|||||||
args: ^2.5.0
|
args: ^2.5.0
|
||||||
equatable: ^2.0.5
|
equatable: ^2.0.5
|
||||||
shlex: ^2.0.2
|
shlex: ^2.0.2
|
||||||
|
apidash_core:
|
||||||
|
path: ../apidash_core
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
lints: ^2.1.0
|
lints: ^2.1.0
|
||||||
|
34
packages/curl_parser/test/curl_model_test.dart
Normal file
34
packages/curl_parser/test/curl_model_test.dart
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import 'package:apidash_core/apidash_core.dart';
|
||||||
|
import 'package:curl_parser/curl_parser.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('should not throw when form data entries are provided', () {
|
||||||
|
expect(
|
||||||
|
() => Curl(
|
||||||
|
uri: Uri.parse('https://api.apidash.dev/upload'),
|
||||||
|
method: 'POST',
|
||||||
|
form: true,
|
||||||
|
formData: [
|
||||||
|
FormDataModel(
|
||||||
|
name: "username", value: "john", type: FormDataType.text),
|
||||||
|
FormDataModel(
|
||||||
|
name: "password", value: "password", type: FormDataType.text),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
returnsNormally,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not throw when form data is null', () {
|
||||||
|
expect(
|
||||||
|
() => Curl(
|
||||||
|
uri: Uri.parse('https://api.apidash.dev/upload'),
|
||||||
|
method: 'POST',
|
||||||
|
form: false,
|
||||||
|
formData: null,
|
||||||
|
),
|
||||||
|
returnsNormally,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
@ -1,233 +1,328 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'package:apidash_core/apidash_core.dart';
|
||||||
import 'package:curl_parser/models/curl.dart';
|
import 'package:curl_parser/curl_parser.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
const defaultTimeout = Timeout(Duration(seconds: 3));
|
final apiUri = Uri.parse('https://api.apidash.dev');
|
||||||
final exampleDotComUri = Uri.parse('https://api.apidash.dev/');
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('parse an easy cURL', () async {
|
test(
|
||||||
|
'parse an easy cURL',
|
||||||
|
() async {
|
||||||
|
expect(
|
||||||
|
Curl.parse('curl -X GET https://api.apidash.dev'),
|
||||||
|
Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: apiUri,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('parse POST request with multipart/form-data', () {
|
||||||
|
const curl = r'''curl -X POST 'https://api.apidash.dev/io/img' \
|
||||||
|
-H 'Content-Type: multipart/form-data' \
|
||||||
|
-F "imfile=@/path/to/image.jpg" \
|
||||||
|
-F "token=john"
|
||||||
|
''';
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
Curl.parse('curl -X GET https://api.apidash.dev/'),
|
Curl.parse(curl),
|
||||||
Curl(
|
Curl(
|
||||||
method: 'GET',
|
method: 'POST',
|
||||||
uri: exampleDotComUri,
|
uri: Uri.parse('https://api.apidash.dev/io/img'),
|
||||||
|
headers: {"Content-Type": "multipart/form-data"},
|
||||||
|
form: true,
|
||||||
|
formData: [
|
||||||
|
FormDataModel(
|
||||||
|
name: "imfile",
|
||||||
|
value: "/path/to/image.jpg",
|
||||||
|
type: FormDataType.file,
|
||||||
|
),
|
||||||
|
FormDataModel(
|
||||||
|
name: "token",
|
||||||
|
value: "john",
|
||||||
|
type: FormDataType.text,
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}, timeout: defaultTimeout);
|
});
|
||||||
|
|
||||||
|
test('parse POST request with x-www-form-urlencoded', () {
|
||||||
|
const curl = r'''curl -X 'POST' \
|
||||||
|
'https://api.apidash.dev/io/form' \
|
||||||
|
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||||
|
-d 'text=apidash&sep=%7C×=3'
|
||||||
|
''';
|
||||||
|
|
||||||
test('compose an easy cURL', () async {
|
|
||||||
expect(
|
expect(
|
||||||
Curl.parse('curl -X GET https://api.apidash.dev/'),
|
Curl.parse(curl),
|
||||||
Curl(
|
Curl(
|
||||||
method: 'GET',
|
method: 'POST',
|
||||||
uri: exampleDotComUri,
|
uri: Uri.parse('https://api.apidash.dev/io/form'),
|
||||||
|
headers: {"Content-Type": "application/x-www-form-urlencoded"},
|
||||||
|
data: 'text=apidash&sep=%7C×=3',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}, timeout: defaultTimeout);
|
});
|
||||||
|
|
||||||
test('Check quotes support for URL string', () async {
|
test('should throw exception when multipart/form-data is not valid', () {
|
||||||
expect(
|
const curl = r'''curl -X POST https://api.apidash.dev/upload \
|
||||||
Curl.parse('curl -X GET "https://api.apidash.dev/"'),
|
-F "invalid_format" \
|
||||||
Curl(
|
-F "username=john"
|
||||||
method: 'GET',
|
''';
|
||||||
uri: exampleDotComUri,
|
expect(() => Curl.parse(curl), throwsException);
|
||||||
),
|
});
|
||||||
);
|
|
||||||
}, timeout: defaultTimeout);
|
|
||||||
|
|
||||||
test('parses two headers', () async {
|
test(
|
||||||
expect(
|
'Check quotes support for URL string',
|
||||||
Curl.parse(
|
() async {
|
||||||
'curl -X GET https://api.apidash.dev/ -H "${HttpHeaders.contentTypeHeader}: ${ContentType.text}" -H "${HttpHeaders.authorizationHeader}: Bearer %token%"',
|
expect(
|
||||||
),
|
Curl.parse('curl -X GET "https://api.apidash.dev"'),
|
||||||
Curl(
|
Curl(method: 'GET', uri: apiUri),
|
||||||
method: 'GET',
|
);
|
||||||
uri: exampleDotComUri,
|
},
|
||||||
headers: {
|
);
|
||||||
HttpHeaders.contentTypeHeader: ContentType.text.toString(),
|
|
||||||
HttpHeaders.authorizationHeader: 'Bearer %token%',
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}, timeout: defaultTimeout);
|
|
||||||
|
|
||||||
test('parses a lot of headers', () async {
|
test(
|
||||||
expect(
|
'parses two headers',
|
||||||
Curl.parse(
|
() async {
|
||||||
r'curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" -H "Upgrade-Insecure-Requests: 1" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7" -H "Accept-Encoding: gzip, deflate, br" -H "Accept-Language: en,en-GB;q=0.9,en-US;q=0.8,ru;q=0.7" -H "Cache-Control: max-age=0" -H "Dnt: 1" -H "Sec-Ch-Ua: \"Google Chrome\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\"" -H "Sec-Ch-Ua-Mobile: ?0" -H "Sec-Ch-Ua-Platform: \"macOS\"" -H "Sec-Fetch-Dest: document" -H "Sec-Fetch-Mode: navigate" -H "Sec-Fetch-Site: same-origin" -H "Sec-Fetch-User: ?1" https://apidash.dev',
|
expect(
|
||||||
),
|
Curl.parse(
|
||||||
Curl(
|
'curl -X GET https://api.apidash.dev -H "${HttpHeaders.contentTypeHeader}: ${ContentType.text}" -H "${HttpHeaders.authorizationHeader}: Bearer %token%"',
|
||||||
method: 'GET',
|
),
|
||||||
uri: Uri.parse('https://apidash.dev'),
|
Curl(
|
||||||
headers: {
|
method: 'GET',
|
||||||
'User-Agent':
|
uri: apiUri,
|
||||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
|
headers: {
|
||||||
'Upgrade-Insecure-Requests': '1',
|
HttpHeaders.contentTypeHeader: ContentType.text.toString(),
|
||||||
'Accept':
|
HttpHeaders.authorizationHeader: 'Bearer %token%',
|
||||||
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
},
|
||||||
'Accept-Encoding': 'gzip, deflate, br',
|
),
|
||||||
'Accept-Language': 'en,en-GB;q=0.9,en-US;q=0.8,ru;q=0.7',
|
);
|
||||||
'Cache-Control': 'max-age=0',
|
},
|
||||||
'Dnt': '1',
|
);
|
||||||
'Sec-Ch-Ua':
|
|
||||||
'"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"',
|
|
||||||
'Sec-Ch-Ua-Mobile': '?0',
|
|
||||||
'Sec-Ch-Ua-Platform': '"macOS"',
|
|
||||||
'Sec-Fetch-Dest': 'document',
|
|
||||||
'Sec-Fetch-Mode': 'navigate',
|
|
||||||
'Sec-Fetch-Site': 'same-origin',
|
|
||||||
'Sec-Fetch-User': '?1'
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}, timeout: defaultTimeout);
|
|
||||||
|
|
||||||
test('throw exception when parses wrong input', () async {
|
test(
|
||||||
expect(
|
'parses a lot of headers',
|
||||||
() => Curl.parse('1f'),
|
() async {
|
||||||
throwsException,
|
expect(
|
||||||
);
|
Curl.parse(
|
||||||
}, timeout: defaultTimeout);
|
r'''curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" \
|
||||||
|
-H "Upgrade-Insecure-Requests: 1" \
|
||||||
|
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7" \
|
||||||
|
-H "Accept-Encoding: gzip, deflate, br" \
|
||||||
|
-H "Accept-Language: en,en-GB;q=0.9,en-US;q=0.8,ru;q=0.7" \
|
||||||
|
-H "Cache-Control: max-age=0" \
|
||||||
|
-H "Dnt: 1" \
|
||||||
|
-H "Sec-Ch-Ua: \"Google Chrome\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\"" \
|
||||||
|
-H "Sec-Ch-Ua-Mobile: ?0" \
|
||||||
|
-H "Sec-Ch-Ua-Platform: \"macOS\"" \
|
||||||
|
-H "Sec-Fetch-Dest: document" \
|
||||||
|
-H "Sec-Fetch-Mode: navigate" \
|
||||||
|
-H "Sec-Fetch-Site: same-origin" \
|
||||||
|
-H "Sec-Fetch-User: ?1" https://apidash.dev''',
|
||||||
|
),
|
||||||
|
Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: Uri.parse('https://apidash.dev'),
|
||||||
|
headers: {
|
||||||
|
'User-Agent':
|
||||||
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
|
||||||
|
'Upgrade-Insecure-Requests': '1',
|
||||||
|
'Accept':
|
||||||
|
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||||
|
'Accept-Encoding': 'gzip, deflate, br',
|
||||||
|
'Accept-Language': 'en,en-GB;q=0.9,en-US;q=0.8,ru;q=0.7',
|
||||||
|
'Cache-Control': 'max-age=0',
|
||||||
|
'Dnt': '1',
|
||||||
|
'Sec-Ch-Ua':
|
||||||
|
'"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"',
|
||||||
|
'Sec-Ch-Ua-Mobile': '?0',
|
||||||
|
'Sec-Ch-Ua-Platform': '"macOS"',
|
||||||
|
'Sec-Fetch-Dest': 'document',
|
||||||
|
'Sec-Fetch-Mode': 'navigate',
|
||||||
|
'Sec-Fetch-Site': 'same-origin',
|
||||||
|
'Sec-Fetch-User': '?1'
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('tryParse return null when parses wrong input', () async {
|
test(
|
||||||
expect(
|
'throw exception when parses wrong input',
|
||||||
Curl.tryParse('1f'),
|
() async {
|
||||||
null,
|
expect(() => Curl.parse('1f'), throwsException);
|
||||||
);
|
},
|
||||||
}, timeout: defaultTimeout);
|
);
|
||||||
|
|
||||||
test('tryParse success', () async {
|
test(
|
||||||
expect(
|
'tryParse return null when parses wrong input',
|
||||||
Curl.tryParse(
|
() async {
|
||||||
'curl -X GET https://api.apidash.dev/ -H "${HttpHeaders.contentTypeHeader}: ${ContentType.text}" -H "${HttpHeaders.authorizationHeader}: Bearer %token%"',
|
expect(Curl.tryParse('1f'), null);
|
||||||
),
|
},
|
||||||
Curl(
|
);
|
||||||
method: 'GET',
|
|
||||||
uri: exampleDotComUri,
|
|
||||||
headers: {
|
|
||||||
HttpHeaders.contentTypeHeader: ContentType.text.toString(),
|
|
||||||
HttpHeaders.authorizationHeader: 'Bearer %token%',
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}, timeout: defaultTimeout);
|
|
||||||
|
|
||||||
test('GET 1', () async {
|
test(
|
||||||
expect(
|
'tryParse success',
|
||||||
Curl.parse(
|
() async {
|
||||||
r"""curl --url 'https://api.apidash.dev'""",
|
expect(
|
||||||
),
|
Curl.tryParse(
|
||||||
Curl(
|
'curl -X GET https://api.apidash.dev -H "test: Agent"',
|
||||||
method: 'GET',
|
),
|
||||||
uri: Uri.parse('https://api.apidash.dev'),
|
Curl(
|
||||||
),
|
method: 'GET',
|
||||||
);
|
uri: apiUri,
|
||||||
}, timeout: defaultTimeout);
|
headers: {
|
||||||
|
'test': 'Agent',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('GET 2', () async {
|
test(
|
||||||
expect(
|
'HEAD 1',
|
||||||
Curl.parse(
|
() async {
|
||||||
r"""curl --url 'https://api.apidash.dev/country/data?code=US'""",
|
expect(
|
||||||
),
|
Curl.parse(
|
||||||
Curl(
|
r"""curl -I 'https://api.apidash.dev'""",
|
||||||
method: 'GET',
|
),
|
||||||
uri: Uri.parse('https://api.apidash.dev/country/data?code=US'),
|
Curl(
|
||||||
),
|
method: 'HEAD',
|
||||||
);
|
uri: apiUri,
|
||||||
}, timeout: defaultTimeout);
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('GET 3', () async {
|
test(
|
||||||
expect(
|
'HEAD 2',
|
||||||
Curl.parse(
|
() async {
|
||||||
r"""curl --url 'https://api.apidash.dev/country/data?code=IND'""",
|
expect(
|
||||||
),
|
Curl.parse(
|
||||||
Curl(
|
r"""curl --head 'https://api.apidash.dev'""",
|
||||||
method: 'GET',
|
),
|
||||||
uri: Uri.parse('https://api.apidash.dev/country/data?code=IND'),
|
Curl(
|
||||||
),
|
method: 'HEAD',
|
||||||
);
|
uri: apiUri,
|
||||||
}, timeout: defaultTimeout);
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('GET 4', () async {
|
test(
|
||||||
expect(
|
'GET 1',
|
||||||
Curl.parse(
|
() async {
|
||||||
r"""curl --url 'https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true'""",
|
expect(
|
||||||
),
|
Curl.parse(
|
||||||
Curl(
|
r"""curl --url 'https://api.apidash.dev'""",
|
||||||
method: 'GET',
|
),
|
||||||
uri: Uri.parse(
|
Curl(
|
||||||
'https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true'),
|
method: 'GET',
|
||||||
),
|
uri: apiUri,
|
||||||
);
|
),
|
||||||
}, timeout: defaultTimeout);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('GET 5', () async {
|
test(
|
||||||
expect(
|
'GET 2',
|
||||||
Curl.parse(
|
() async {
|
||||||
r"""curl --url 'https://api.github.com/repos/foss42/apidash' \
|
expect(
|
||||||
|
Curl.parse(
|
||||||
|
r"""curl --url 'https://api.apidash.dev/country/data?code=US'""",
|
||||||
|
),
|
||||||
|
Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev/country/data?code=US'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'GET 3',
|
||||||
|
() async {
|
||||||
|
expect(
|
||||||
|
Curl.parse(
|
||||||
|
r"""curl 'https://api.apidash.dev/country/data?code=IND'""",
|
||||||
|
),
|
||||||
|
Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev/country/data?code=IND'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'GET with GitHub API',
|
||||||
|
() async {
|
||||||
|
expect(
|
||||||
|
Curl.parse(
|
||||||
|
r"""curl --url 'https://api.github.com/repos/foss42/apidash' \
|
||||||
--header 'User-Agent: Test Agent'""",
|
--header 'User-Agent: Test Agent'""",
|
||||||
),
|
),
|
||||||
Curl(
|
Curl(
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
uri: Uri.parse('https://api.github.com/repos/foss42/apidash'),
|
uri: Uri.parse('https://api.github.com/repos/foss42/apidash'),
|
||||||
headers: {"User-Agent": "Test Agent"},
|
headers: {"User-Agent": "Test Agent"},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}, timeout: defaultTimeout);
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('GET 6', () async {
|
test(
|
||||||
expect(
|
'GET with GitHub API and raw parameter',
|
||||||
Curl.parse(
|
() async {
|
||||||
r"""curl --url 'https://api.github.com/repos/foss42/apidash?raw=true' \
|
expect(
|
||||||
|
Curl.parse(
|
||||||
|
r"""curl --url 'https://api.github.com/repos/foss42/apidash?raw=true' \
|
||||||
--header 'User-Agent: Test Agent'""",
|
--header 'User-Agent: Test Agent'""",
|
||||||
),
|
),
|
||||||
Curl(
|
Curl(
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
uri: Uri.parse('https://api.github.com/repos/foss42/apidash?raw=true'),
|
uri:
|
||||||
headers: {"User-Agent": "Test Agent"},
|
Uri.parse('https://api.github.com/repos/foss42/apidash?raw=true'),
|
||||||
),
|
headers: {"User-Agent": "Test Agent"},
|
||||||
);
|
),
|
||||||
}, timeout: defaultTimeout);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('HEAD 2', () async {
|
test(
|
||||||
expect(
|
'POST with text/plain content',
|
||||||
Curl.parse(
|
() async {
|
||||||
r"""curl --head --url 'http://api.apidash.dev'""",
|
expect(
|
||||||
),
|
Curl.parse(
|
||||||
Curl(
|
r"""curl --request POST \
|
||||||
method: 'HEAD',
|
|
||||||
uri: Uri.parse('http://api.apidash.dev'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}, timeout: defaultTimeout);
|
|
||||||
|
|
||||||
test('POST 1', () async {
|
|
||||||
expect(
|
|
||||||
Curl.parse(
|
|
||||||
r"""curl --request POST \
|
|
||||||
--url 'https://api.apidash.dev/case/lower' \
|
--url 'https://api.apidash.dev/case/lower' \
|
||||||
--header 'Content-Type: text/plain' \
|
--header 'Content-Type: text/plain' \
|
||||||
--data '{
|
--data '{
|
||||||
"text": "I LOVE Flutter"
|
"text": "I LOVE Flutter"
|
||||||
}'""",
|
}'""",
|
||||||
),
|
),
|
||||||
Curl(
|
Curl(
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
uri: Uri.parse('https://api.apidash.dev/case/lower'),
|
uri: Uri.parse('https://api.apidash.dev/case/lower'),
|
||||||
headers: {"Content-Type": "text/plain"},
|
headers: {"Content-Type": "text/plain"},
|
||||||
data: r"""{
|
data: r"""{
|
||||||
"text": "I LOVE Flutter"
|
"text": "I LOVE Flutter"
|
||||||
}""",
|
}""",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}, timeout: defaultTimeout);
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('POST 2', () async {
|
test(
|
||||||
expect(
|
'POST with application/json content',
|
||||||
Curl.parse(
|
() async {
|
||||||
r"""curl --request POST \
|
expect(
|
||||||
|
Curl.parse(
|
||||||
|
r"""curl --request POST \
|
||||||
--url 'https://api.apidash.dev/case/lower' \
|
--url 'https://api.apidash.dev/case/lower' \
|
||||||
--header 'Content-Type: application/json' \
|
--header 'Content-Type: application/json' \
|
||||||
--data '{
|
--data '{
|
||||||
@ -238,12 +333,12 @@ void main() {
|
|||||||
"no": 1.2,
|
"no": 1.2,
|
||||||
"arr": ["null", "true", "false", null]
|
"arr": ["null", "true", "false", null]
|
||||||
}'""",
|
}'""",
|
||||||
),
|
),
|
||||||
Curl(
|
Curl(
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
uri: Uri.parse('https://api.apidash.dev/case/lower'),
|
uri: Uri.parse('https://api.apidash.dev/case/lower'),
|
||||||
headers: {"Content-Type": "application/json"},
|
headers: {"Content-Type": "application/json"},
|
||||||
data: r"""{
|
data: r"""{
|
||||||
"text": "I LOVE Flutter",
|
"text": "I LOVE Flutter",
|
||||||
"flag": null,
|
"flag": null,
|
||||||
"male": true,
|
"male": true,
|
||||||
@ -251,7 +346,8 @@ void main() {
|
|||||||
"no": 1.2,
|
"no": 1.2,
|
||||||
"arr": ["null", "true", "false", null]
|
"arr": ["null", "true", "false", null]
|
||||||
}""",
|
}""",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}, timeout: defaultTimeout);
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
252
packages/curl_parser/test/dart_to_curl_test.dart
Normal file
252
packages/curl_parser/test/dart_to_curl_test.dart
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
import 'package:apidash_core/apidash_core.dart';
|
||||||
|
import 'package:curl_parser/curl_parser.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group(
|
||||||
|
'Basic HTTP Methods',
|
||||||
|
() {
|
||||||
|
test(
|
||||||
|
'GET request',
|
||||||
|
() {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
'curl "https://api.apidash.dev"',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'POST request',
|
||||||
|
() {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'POST',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev/test'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
'curl -X POST "https://api.apidash.dev/test"',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('HEAD request', () {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'HEAD',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
'curl -I "https://api.apidash.dev"',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
group(
|
||||||
|
'Headers and Data',
|
||||||
|
() {
|
||||||
|
test(
|
||||||
|
'request with headers',
|
||||||
|
() {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer token123'
|
||||||
|
},
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
r'''curl "https://api.apidash.dev" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer token123"''',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('POST request with data', () {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'POST',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev/case/lower'),
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
data: '{"text": "Grass Is Green"}',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
r"""curl -X POST "https://api.apidash.dev/case/lower" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"text": "Grass Is Green"}'""",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
group(
|
||||||
|
'Post with Form Data',
|
||||||
|
() {
|
||||||
|
test('request with form data', () {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'POST',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev/io/img'),
|
||||||
|
headers: {'Content-Type': 'multipart/form-data'},
|
||||||
|
form: true,
|
||||||
|
formData: [
|
||||||
|
FormDataModel(
|
||||||
|
name: "imfile",
|
||||||
|
value: "/path/to/file.png",
|
||||||
|
type: FormDataType.file,
|
||||||
|
),
|
||||||
|
FormDataModel(
|
||||||
|
name: "token",
|
||||||
|
value: "123",
|
||||||
|
type: FormDataType.text,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
r'''curl -X POST "https://api.apidash.dev/io/img" \
|
||||||
|
-H "Content-Type: multipart/form-data" \
|
||||||
|
-F "imfile=@/path/to/file.png" \
|
||||||
|
-F "token=123"''',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
group(
|
||||||
|
'Special Parameters',
|
||||||
|
() {
|
||||||
|
test(
|
||||||
|
'request with cookie',
|
||||||
|
() {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
|
cookie: 'session=abc123',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
r"""curl "https://api.apidash.dev" \
|
||||||
|
-b 'session=abc123'""",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'request with user credentials',
|
||||||
|
() {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
|
user: 'username:password',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
r"""curl "https://api.apidash.dev" \
|
||||||
|
-u 'username:password'""",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'request with referer',
|
||||||
|
() {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
|
referer: 'https://example.com',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
r"""curl "https://api.apidash.dev" \
|
||||||
|
-e 'https://example.com'""",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'request with user agent',
|
||||||
|
() {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
|
userAgent: 'MyApp/1.0',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
r"""curl "https://api.apidash.dev" \
|
||||||
|
-A 'MyApp/1.0'""",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'request with insecure flag',
|
||||||
|
() {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
|
insecure: true,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
r"""curl "https://api.apidash.dev" -k""",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('request with location flag', () {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev'),
|
||||||
|
location: true,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
r"""curl "https://api.apidash.dev" -L""",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
group(
|
||||||
|
'Complex Requests',
|
||||||
|
() {
|
||||||
|
test('request with all parameters', () {
|
||||||
|
final curl = Curl(
|
||||||
|
method: 'POST',
|
||||||
|
uri: Uri.parse('https://api.apidash.dev/test'),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer token123'
|
||||||
|
},
|
||||||
|
data: '{"key": "value"}',
|
||||||
|
cookie: 'session=abc123',
|
||||||
|
user: 'username:password',
|
||||||
|
referer: 'https://example.com',
|
||||||
|
userAgent: 'MyApp/1.0',
|
||||||
|
insecure: true,
|
||||||
|
location: true,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
curl.toCurlString(),
|
||||||
|
r"""curl -X POST "https://api.apidash.dev/test" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer token123" \
|
||||||
|
-d '{"key": "value"}' \
|
||||||
|
-b 'session=abc123' \
|
||||||
|
-u 'username:password' \
|
||||||
|
-e 'https://example.com' \
|
||||||
|
-A 'MyApp/1.0' -k -L""",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
Reference in New Issue
Block a user