Skip to content

Commit d5d65a9

Browse files
committed
fixed formatting
1 parent 97eea80 commit d5d65a9

3 files changed

Lines changed: 33 additions & 47 deletions

File tree

lib/src/request.dart

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,9 @@ class AwsHttpRequest {
156156
stackTrace: StackTrace.current);
157157
}
158158
}
159-
final String? contentTypeKey = headers.keys
160-
.cast<String?>()
161-
.firstWhere((k) => k!.toLowerCase() == 'content-type',
162-
orElse: () => null);
159+
final String? contentTypeKey = headers.keys.cast<String?>().firstWhere(
160+
(k) => k!.toLowerCase() == 'content-type',
161+
orElse: () => null);
163162
if (contentTypeKey != null) {
164163
signedHeaders['content-type'] = headers[contentTypeKey]!;
165164
}
@@ -196,29 +195,26 @@ class AwsHttpRequest {
196195
}) {
197196
// Sort by header name only (AWS), not by the full "name:value" line — a
198197
// prefix name like "a" must sort before "a1" (":" > "1" would break line sort).
199-
final List<MapEntry<String, String>> lowered =
200-
signedHeaders.entries
201-
.map(
202-
(MapEntry<String, String> e) => MapEntry<String, String>(
203-
e.key.toLowerCase(),
204-
e.value,
205-
),
206-
)
207-
.toList()
208-
..sort(
209-
(MapEntry<String, String> a, MapEntry<String, String> b) =>
210-
a.key.compareTo(b.key),
211-
);
198+
final List<MapEntry<String, String>> lowered = signedHeaders.entries
199+
.map(
200+
(MapEntry<String, String> e) => MapEntry<String, String>(
201+
e.key.toLowerCase(),
202+
e.value,
203+
),
204+
)
205+
.toList()
206+
..sort(
207+
(MapEntry<String, String> a, MapEntry<String, String> b) =>
208+
a.key.compareTo(b.key),
209+
);
212210
final String canonicalHeadersString = lowered
213211
.map(
214212
(MapEntry<String, String> e) =>
215213
'${e.key}:${canonicalHeaderValueForSigV4(e.value)}\n',
216214
)
217215
.join('');
218-
final List<String> keyList = signedHeaders.keys
219-
.map((String k) => k.toLowerCase())
220-
.toList()
221-
..sort();
216+
final List<String> keyList =
217+
signedHeaders.keys.map((String k) => k.toLowerCase()).toList()..sort();
222218
final String signedHeaderKeys = keyList.join(';');
223219
final String payloadHash = hashedPayloadIsUnsigned
224220
? sha256.convert(utf8.encode('UNSIGNED-PAYLOAD')).toString()
@@ -257,10 +253,8 @@ class AwsHttpRequest {
257253
serviceName: serviceLc,
258254
stringToSign: stringToSign,
259255
);
260-
final List<String> keyList = signedHeaders.keys
261-
.map((String k) => k.toLowerCase())
262-
.toList()
263-
..sort();
256+
final List<String> keyList =
257+
signedHeaders.keys.map((String k) => k.toLowerCase()).toList()..sort();
264258
final String signedHeaderKeys = keyList.join(';');
265259
return '$algorithm Credential=$awsAccessKey/$credentialScope, '
266260
'SignedHeaders=$signedHeaderKeys, '

test/live_aws_tests.dart

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@ const String _iamSignRegion = 'us-east-1';
4747

4848
final class _LiveAwsCreds {
4949
_LiveAwsCreds._(this.env)
50-
: region =
51-
env['AWS_DEFAULT_REGION'] ?? env['AWS_REGION'] ?? 'us-east-1',
50+
: region = env['AWS_DEFAULT_REGION'] ?? env['AWS_REGION'] ?? 'us-east-1',
5251
accessKey = env['AWS_ACCESS_KEY_ID']!,
5352
secretKey = env['AWS_SECRET_ACCESS_KEY']!,
5453
sessionToken = env['AWS_SESSION_TOKEN'],
55-
hasSessionToken =
56-
(env['AWS_SESSION_TOKEN'] ?? '').trim().isNotEmpty;
54+
hasSessionToken = (env['AWS_SESSION_TOKEN'] ?? '').trim().isNotEmpty;
5755

5856
factory _LiveAwsCreds.fromEnv(Map<String, String> env) =>
5957
_LiveAwsCreds._(env);
@@ -232,7 +230,8 @@ void _expect200OrAwsAccessDenied(
232230
expect(
233231
_awsAccessDeniedLike.hasMatch(response.body),
234232
isTrue,
235-
reason: 'Expected AWS access / authorization style body, got: ${response.body}',
233+
reason:
234+
'Expected AWS access / authorization style body, got: ${response.body}',
236235
);
237236
}
238237

@@ -291,8 +290,7 @@ void main() {
291290
expect(
292291
_awsSigV4OrCredentialFailureLike.hasMatch(response.body),
293292
isTrue,
294-
reason:
295-
'Expected AWS SigV4/signature/credential error in body, got '
293+
reason: 'Expected AWS SigV4/signature/credential error in body, got '
296294
'status=${response.statusCode}: ${response.body}',
297295
);
298296
},
@@ -301,15 +299,15 @@ void main() {
301299

302300
// IAM JSON RPC (`X-Amz-Target`) has returned 302 redirects for some clients
303301
// hitting `iam.amazonaws.com`; the Query API matches STS and is stable here.
304-
test('iam:GetUser (Query POST, XML, caller when UserName omitted)', () async {
302+
test('iam:GetUser (Query POST, XML, caller when UserName omitted)',
303+
() async {
305304
final Response response = await c.postForm(
306305
service: 'iam',
307306
region: _iamSignRegion,
308307
endpoint: 'iam.amazonaws.com',
309308
body: 'Action=GetUser&Version=2010-05-08',
310309
);
311-
_expect200OrAwsAccessDenied(response,
312-
context: 'iam:GetUser',
310+
_expect200OrAwsAccessDenied(response, context: 'iam:GetUser',
313311
onOk: (Response ok) {
314312
expect(ok.body, contains('GetUserResponse'));
315313
});
@@ -321,8 +319,7 @@ void main() {
321319
region: c.region,
322320
body: 'Action=DescribeRegions&Version=2016-11-15',
323321
);
324-
_expect200OrAwsAccessDenied(response,
325-
context: 'ec2:DescribeRegions',
322+
_expect200OrAwsAccessDenied(response, context: 'ec2:DescribeRegions',
326323
onOk: (Response ok) {
327324
expect(ok.body, contains('DescribeRegionsResponse'));
328325
expect(ok.body, contains('regionName'));
@@ -335,8 +332,7 @@ void main() {
335332
region: c.region,
336333
body: 'Action=ListQueues&Version=2012-11-05',
337334
);
338-
_expect200OrAwsAccessDenied(response,
339-
context: 'sqs:ListQueues',
335+
_expect200OrAwsAccessDenied(response, context: 'sqs:ListQueues',
340336
onOk: (Response ok) {
341337
expect(ok.body, contains('ListQueuesResponse'));
342338
});
@@ -349,8 +345,7 @@ void main() {
349345
target: 'AWSLambda_20150331.ListFunctions',
350346
jsonBody: '{"MaxItems":1}',
351347
);
352-
_expect200OrAwsAccessDenied(response,
353-
context: 'lambda:ListFunctions',
348+
_expect200OrAwsAccessDenied(response, context: 'lambda:ListFunctions',
354349
onOk: (Response ok) {
355350
expect(ok.body, contains('"Functions"'));
356351
});
@@ -363,8 +358,7 @@ void main() {
363358
target: 'TrentService.ListKeys',
364359
jsonBody: '{"Limit":1}',
365360
);
366-
_expect200OrAwsAccessDenied(response,
367-
context: 'kms:ListKeys',
361+
_expect200OrAwsAccessDenied(response, context: 'kms:ListKeys',
368362
onOk: (Response ok) {
369363
expect(ok.body, contains('"Keys"'));
370364
});
@@ -376,8 +370,7 @@ void main() {
376370
region: c.region,
377371
body: 'Action=ListTopics&Version=2010-03-31',
378372
);
379-
_expect200OrAwsAccessDenied(response,
380-
context: 'sns:ListTopics',
373+
_expect200OrAwsAccessDenied(response, context: 'sns:ListTopics',
381374
onOk: (Response ok) {
382375
expect(ok.body, contains('ListTopicsResponse'));
383376
});

test/mock_aws_request_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ void main() {
135135
mockFunction: (Request request) async {
136136
return Response('', 200);
137137
},
138-
)
139-
..service = 'service';
138+
)..service = 'service';
140139
await awsRequest.send(type: AwsRequestType.get);
141140
} catch (e) {
142141
print(e);

0 commit comments

Comments
 (0)