Skip to content

Commit a452dbf

Browse files
add maven sign unit test (#175)
1 parent f7f4362 commit a452dbf

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

tests/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ def setUp(self):
4343
- ".*^(redhat).*"
4444
- ".*snapshot.*"
4545
46+
ignore_signature_suffix:
47+
maven:
48+
- ".sha1"
49+
- ".sha256"
50+
- ".md5"
51+
- "maven-metadata.xml"
52+
- "archtype-catalog.xml"
53+
npm:
54+
- "package.json"
55+
56+
detach_signature_command: "touch {{ file }}.asc"
57+
4658
targets:
4759
ga:
4860
- bucket: "charon-test"

tests/commons.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@
8989
COMMONS_CLIENT_456_INDEX = "org/apache/httpcomponents/httpclient/4.5.6/index.html"
9090
COMMONS_LOGGING_INDEX = "commons-logging/commons-logging/index.html"
9191
COMMONS_ROOT_INDEX = "index.html"
92+
COMMONS_LOGGING_SIGNS = [
93+
"commons-logging/commons-logging/1.2/commons-logging-1.2.jar.asc",
94+
"commons-logging/commons-logging/1.2/commons-logging-1.2-sources.jar.asc",
95+
"commons-logging/commons-logging/1.2/commons-logging-1.2.pom.asc",
96+
]
97+
COMMONS_CLIENT_456_SIGNS = [
98+
"org/apache/httpcomponents/httpclient/4.5.6/httpclient-4.5.6.jar.asc",
99+
"org/apache/httpcomponents/httpclient/4.5.6/httpclient-4.5.6.pom.asc",
100+
]
101+
COMMONS_CLIENT_459_SIGNS = [
102+
"org/apache/httpcomponents/httpclient/4.5.9/httpclient-4.5.9.jar.asc",
103+
"org/apache/httpcomponents/httpclient/4.5.9/httpclient-4.5.9.pom.asc",
104+
]
92105

93106

94107
# For npm

tests/test_maven_sign.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""
2+
Copyright (C) 2022 Red Hat, Inc. (https://github.com/Commonjava/charon)
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
"""
16+
from charon.pkgs.maven import handle_maven_uploading
17+
from tests.base import PackageBaseTest
18+
from tests.commons import (
19+
TEST_BUCKET, COMMONS_CLIENT_456_SIGNS, COMMONS_LOGGING_SIGNS, COMMONS_CLIENT_456_INDEX,
20+
COMMONS_CLIENT_459_SIGNS
21+
)
22+
from moto import mock_s3
23+
import os
24+
25+
from tests.constants import INPUTS
26+
27+
28+
@mock_s3
29+
class MavenFileSignTest(PackageBaseTest):
30+
31+
def test_uploading_sign(self):
32+
test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip")
33+
product = "commons-client-4.5.6"
34+
handle_maven_uploading(
35+
test_zip, product,
36+
buckets=[('', TEST_BUCKET, '', '')],
37+
dir_=self.tempdir,
38+
gen_sign=True,
39+
key="random"
40+
)
41+
42+
test_bucket = self.mock_s3.Bucket(TEST_BUCKET)
43+
objs = list(test_bucket.objects.all())
44+
actual_files = [obj.key for obj in objs]
45+
46+
self.assertEqual(46, len(actual_files))
47+
48+
for f in COMMONS_LOGGING_SIGNS:
49+
self.assertIn(f, actual_files)
50+
51+
for f in COMMONS_CLIENT_456_SIGNS:
52+
self.assertIn(f, actual_files)
53+
54+
indedx_obj = test_bucket.Object(COMMONS_CLIENT_456_INDEX)
55+
index_content = str(indedx_obj.get()["Body"].read(), "utf-8")
56+
self.assertIn(
57+
"<a href=\"httpclient-4.5.6.jar.asc\" "
58+
"title=\"httpclient-4.5.6.jar.asc\">httpclient-4.5.6.jar.asc</a>",
59+
index_content
60+
)
61+
62+
def test_overlap_upload_index(self):
63+
test_zip = os.path.join(INPUTS, "commons-client-4.5.6.zip")
64+
product_456 = "commons-client-4.5.6"
65+
handle_maven_uploading(
66+
test_zip, product_456,
67+
buckets=[('', TEST_BUCKET, '', '')],
68+
dir_=self.tempdir,
69+
gen_sign=True,
70+
key="random"
71+
)
72+
73+
test_zip = os.path.join(INPUTS, "commons-client-4.5.9.zip")
74+
product_459 = "commons-client-4.5.9"
75+
handle_maven_uploading(
76+
test_zip, product_459,
77+
buckets=[('', TEST_BUCKET, '', '')],
78+
dir_=self.tempdir,
79+
gen_sign=True,
80+
key="random"
81+
)
82+
83+
test_bucket = self.mock_s3.Bucket(TEST_BUCKET)
84+
objs = list(test_bucket.objects.all())
85+
actual_files = [obj.key for obj in objs]
86+
87+
self.assertEqual(57, len(objs))
88+
89+
for f in COMMONS_LOGGING_SIGNS:
90+
self.assertIn(f, actual_files)
91+
92+
for f in COMMONS_CLIENT_456_SIGNS:
93+
self.assertIn(f, actual_files)
94+
95+
for f in COMMONS_CLIENT_459_SIGNS:
96+
self.assertIn(f, actual_files)

0 commit comments

Comments
 (0)