Skip to content

Commit 2e6799c

Browse files
authored
Fix CodeQL findings (#5698)
* Fix incomplete url substring sanitization, implicit string concatenation, and wrong number of arguments in a call code scanning alerts. * Remove unnecessary passes
1 parent e47af17 commit 2e6799c

File tree

10 files changed

+124
-129
lines changed

10 files changed

+124
-129
lines changed

cli/src/pcluster/api/awslambda/serverless_wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def get_script_name(headers, request_context):
108108
"1",
109109
]
110110

111-
if "amazonaws.com" in headers.get("Host", "") and not strip_stage_path:
111+
if headers.get("Host", "").endswith(".amazonaws.com") and not strip_stage_path:
112112
script_name = "/{}".format(request_context.get("stage", ""))
113113
else:
114114
script_name = ""

cli/tests/pcluster/models/test_cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def test_get_stack_template(self, cluster, mocker, template_body, error_message)
224224
None,
225225
"No UpDatES ARE TO BE PERformed",
226226
"some longer message also containing no updates are to be performed and more words at the end"
227-
"some other error message",
227+
+ "some other error message",
228228
],
229229
)
230230
def test_update_stack_template(self, cluster, mocker, error_message):

cli/tests/pcluster/models/test_imagebuilder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
[
7474
"Kms Key Id key_id is specified, the encrypted state must be True.",
7575
"Root volume size 25 GB is less than the minimum required size 50 GB that equals parent ami"
76-
" volume size.",
76+
+ " volume size.",
7777
],
7878
[FailureLevel.ERROR, FailureLevel.ERROR],
7979
)
@@ -120,11 +120,11 @@ def test_imagebuilder_kms_key_id_encrypted_validator_and_ami_volume_size_validat
120120
URLError("[Errno 2] No such file or directory: '/test/aws-parallelcluster-cookbook-3.0.tgz'"),
121121
[
122122
"The url 'https:///test/aws-parallelcluster-cookbook-3.0.tgz' causes URLError, the error reason is "
123-
"'[Errno 2] No such file or directory: '/test/aws-parallelcluster-cookbook-3.0.tgz''",
123+
+ "'[Errno 2] No such file or directory: '/test/aws-parallelcluster-cookbook-3.0.tgz''",
124124
"Failed when accessing object 'aws-parallelcluster-node-3.0.tgz' from bucket 'test'. This can be due "
125-
"to 'aws-parallelcluster-node-3.0.tgz' not found in 'test'",
125+
+ "to 'aws-parallelcluster-node-3.0.tgz' not found in 'test'",
126126
"The value 'ftp://test/aws-parallelcluster-batch-3.0.tgz' is not a valid URL, choose URL with "
127-
"'https' or 's3' prefix.",
127+
+ "'https' or 's3' prefix.",
128128
],
129129
[FailureLevel.WARNING, FailureLevel.WARNING, FailureLevel.ERROR],
130130
),
@@ -439,7 +439,7 @@ def test_get_stack_events(self, image_builder, mocker, stack_exists, expected_er
439439
"ResourceType": "AWS::CloudFormation::Stack",
440440
"StackId": "arn:aws:cloudformation:us-east-1:000000000000:stack/img",
441441
"StackName": "img",
442-
"Timestamp": datetime.datetime(2021, 7, 13, 2, 20, 20, 000000, tzinfo=tz.tzutc()),
442+
"Timestamp": datetime.datetime(2021, 7, 13, 2, 20, 20, 0o00000, tzinfo=tz.tzutc()),
443443
}
444444
],
445445
}

cli/tests/pcluster/templates/test_imagebuilder_stack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ def test_imagebuilder_instance_role(
13561356
{"Ref": "AWS::Partition"},
13571357
":iam::",
13581358
{"Ref": "AWS::AccountId"},
1359-
":role/parallelcluster/" "ParallelClusterImageCleanup-",
1359+
":role/parallelcluster/ParallelClusterImageCleanup-",
13601360
{"Fn::Select": [2, {"Fn::Split": ["/", {"Ref": "AWS::StackId"}]}]},
13611361
],
13621362
]
@@ -1839,7 +1839,7 @@ def test_imagebuilder_instance_role(
18391839
{"Ref": "AWS::Partition"},
18401840
":iam::",
18411841
{"Ref": "AWS::AccountId"},
1842-
":role/parallelcluster/" "ParallelClusterImageCleanup-",
1842+
":role/parallelcluster/ParallelClusterImageCleanup-",
18431843
{"Fn::Select": [2, {"Fn::Split": ["/", {"Ref": "AWS::StackId"}]}]},
18441844
],
18451845
]

cli/tests/pcluster/validators/test_cluster_validators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,11 +3202,11 @@ def test_root_volume_encryption_consistency_validator(
32023202
],
32033203
[
32043204
"The queue queue_1 contains an instance type with multiple network interfaces however the "
3205-
"AssignPublicIp value is set to true. AWS public IPs can only be assigned to instances "
3206-
"launched with a single network interface.",
3205+
+ "AssignPublicIp value is set to true. AWS public IPs can only be assigned to instances "
3206+
+ "launched with a single network interface.",
32073207
"The queue queue_1 contains an instance type with multiple network interfaces however the subnets "
3208-
"['subnet_1'] is configured to automatically assign public IPs. AWS public IPs can only be assigned "
3209-
"to instances launched with a single network interface.",
3208+
+ "['subnet_1'] is configured to automatically assign public IPs. AWS public IPs can only be assigned "
3209+
+ "to instances launched with a single network interface.",
32103210
],
32113211
id="Test with multi nic queue with assigned public ip and subnet with public ip",
32123212
),

0 commit comments

Comments
 (0)