mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-15 11:57:59 +00:00
initial commit for JFrog support
# Conflicts: # api/api_test.go # api/router.go # go.mod # go.sum # utils/config_test.go
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
from lib import BaseTest
|
||||
import uuid
|
||||
import os
|
||||
|
||||
try:
|
||||
import requests
|
||||
|
||||
if 'JFROG_URL' in os.environ and 'JFROG_USERNAME' in os.environ and \
|
||||
os.environ['JFROG_URL'] != "" and os.environ['JFROG_USERNAME'] != "":
|
||||
jfrog_ready = True
|
||||
else:
|
||||
print("JFrog tests disabled: JFrog creds not found in the environment (JFROG_URL, JFROG_USERNAME, JFROG_PASSWORD)")
|
||||
jfrog_ready = False
|
||||
except ImportError as e:
|
||||
print("JFrog tests disabled: can't import requests", e)
|
||||
jfrog_ready = False
|
||||
|
||||
|
||||
class JFrogTest(BaseTest):
|
||||
"""
|
||||
BaseTest + support for JFrog
|
||||
"""
|
||||
|
||||
jfrogOverrides = {}
|
||||
|
||||
def fixture_available(self):
|
||||
return super(JFrogTest, self).fixture_available() and jfrog_ready
|
||||
|
||||
def prepare(self):
|
||||
self.repository = "aptly-sys-test-" + str(uuid.uuid1())
|
||||
self.jfrog_url = os.environ["JFROG_URL"]
|
||||
self.jfrog_username = os.environ["JFROG_USERNAME"]
|
||||
self.jfrog_password = os.environ["JFROG_PASSWORD"]
|
||||
|
||||
# Create repository via REST API
|
||||
auth = (self.jfrog_username, self.jfrog_password)
|
||||
create_url = f"{self.jfrog_url}/api/repositories/{self.repository}"
|
||||
payload = {
|
||||
"key": self.repository,
|
||||
"rclass": "local",
|
||||
"packageType": "generic"
|
||||
}
|
||||
res = requests.put(create_url, json=payload, auth=auth)
|
||||
if res.status_code >= 400:
|
||||
raise Exception(f"Failed to create JFrog repository: {res.text}")
|
||||
|
||||
self.configOverride = {"JFrogPublishEndpoints": {
|
||||
"test1": {
|
||||
"url": self.jfrog_url,
|
||||
"repository": self.repository,
|
||||
"username": self.jfrog_username,
|
||||
"password": self.jfrog_password
|
||||
}
|
||||
}}
|
||||
|
||||
self.configOverride["JFrogPublishEndpoints"]["test1"].update(**self.jfrogOverrides)
|
||||
|
||||
super(JFrogTest, self).prepare()
|
||||
|
||||
def shutdown(self):
|
||||
if hasattr(self, "repository"):
|
||||
auth = (self.jfrog_username, self.jfrog_password)
|
||||
delete_url = f"{self.jfrog_url}/api/repositories/{self.repository}"
|
||||
requests.delete(delete_url, auth=auth)
|
||||
|
||||
super(JFrogTest, self).shutdown()
|
||||
|
||||
|
||||
def check_path(self, path):
|
||||
if path.startswith("public/"):
|
||||
path = path[7:]
|
||||
|
||||
# Check against JFrog Artifactory API
|
||||
auth = (self.jfrog_username, self.jfrog_password)
|
||||
check_url = f"{self.jfrog_url}/api/storage/{self.repository}/{path}"
|
||||
res = requests.head(check_url, auth=auth)
|
||||
if res.status_code == 200:
|
||||
return True
|
||||
return False
|
||||
|
||||
def check_exists(self, path):
|
||||
if not self.check_path(path):
|
||||
raise Exception("path %s doesn't exist" % (path, ))
|
||||
|
||||
def check_not_exists(self, path):
|
||||
if self.check_path(path):
|
||||
raise Exception("path %s exists" % (path, ))
|
||||
|
||||
def read_file(self, path, mode=''):
|
||||
assert not mode
|
||||
if path.startswith("public/"):
|
||||
path = path[7:]
|
||||
|
||||
auth = (self.jfrog_username, self.jfrog_password)
|
||||
get_url = f"{self.jfrog_url}/{self.repository}/{path}"
|
||||
res = requests.get(get_url, auth=auth)
|
||||
res.raise_for_status()
|
||||
return res.text
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
from jfrog_lib import JFrogTest
|
||||
|
||||
|
||||
def strip_processor(output):
|
||||
return '\n'.join(
|
||||
[
|
||||
l
|
||||
for l in output.split('\n')
|
||||
if not l.startswith(' ') and not l.startswith('Date:')
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class JFrogPublish1Test(JFrogTest):
|
||||
"""
|
||||
publish to JFrog: from repo
|
||||
"""
|
||||
|
||||
fixtureCmds = [
|
||||
'aptly repo create -distribution=maverick local-repo',
|
||||
'aptly repo add local-repo ${files}',
|
||||
'aptly repo remove local-repo libboost-program-options-dev_1.62.0.1_i386',
|
||||
]
|
||||
runCmd = 'aptly publish repo -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec local-repo jfrog:test1:'
|
||||
|
||||
def check(self):
|
||||
self.check_exists('public/dists/maverick/InRelease')
|
||||
self.check_exists('public/dists/maverick/Release')
|
||||
self.check_exists('public/dists/maverick/Release.gpg')
|
||||
|
||||
self.check_exists('public/dists/maverick/main/binary-i386/Packages')
|
||||
self.check_exists('public/dists/maverick/main/binary-i386/Packages.gz')
|
||||
self.check_exists('public/dists/maverick/main/binary-i386/Packages.bz2')
|
||||
self.check_exists('public/dists/maverick/main/source/Sources')
|
||||
self.check_exists('public/dists/maverick/main/source/Sources.gz')
|
||||
self.check_exists('public/dists/maverick/main/source/Sources.bz2')
|
||||
|
||||
self.check_exists('public/pool/main/p/pyspi/pyspi_0.6.1-1.3.dsc')
|
||||
self.check_exists('public/pool/main/p/pyspi/pyspi_0.6.1-1.3.diff.gz')
|
||||
self.check_exists('public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz')
|
||||
self.check_exists('public/pool/main/p/pyspi/pyspi-0.6.1-1.3.stripped.dsc')
|
||||
self.check_exists(
|
||||
'public/pool/main/b/boost-defaults/libboost-program-options-dev_1.49.0.1_i386.deb'
|
||||
)
|
||||
|
||||
# verify contents except sums/date chunks
|
||||
self.check_file_contents(
|
||||
'public/dists/maverick/Release', 'release', match_prepare=strip_processor
|
||||
)
|
||||
self.check_file_contents(
|
||||
'public/dists/maverick/main/source/Sources',
|
||||
'sources',
|
||||
match_prepare=lambda s: '\n'.join(sorted(s.split('\n'))),
|
||||
)
|
||||
self.check_file_contents(
|
||||
'public/dists/maverick/main/binary-i386/Packages',
|
||||
'binary',
|
||||
match_prepare=lambda s: '\n'.join(sorted(s.split('\n'))),
|
||||
)
|
||||
|
||||
|
||||
class JFrogPublish2Test(JFrogTest):
|
||||
"""
|
||||
publish to JFrog: update after removing package from repo
|
||||
"""
|
||||
|
||||
fixtureCmds = [
|
||||
'aptly repo create -distribution=maverick local-repo',
|
||||
'aptly repo add local-repo ${files}/',
|
||||
'aptly repo remove local-repo libboost-program-options-dev_1.62.0.1_i386',
|
||||
'aptly publish repo -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec local-repo jfrog:test1:',
|
||||
'aptly repo remove local-repo pyspi',
|
||||
]
|
||||
runCmd = 'aptly publish update -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec maverick jfrog:test1:'
|
||||
|
||||
def check(self):
|
||||
self.check_exists('public/dists/maverick/InRelease')
|
||||
self.check_exists('public/dists/maverick/Release')
|
||||
self.check_exists('public/dists/maverick/Release.gpg')
|
||||
|
||||
self.check_not_exists('public/pool/main/p/pyspi/pyspi_0.6.1-1.3.dsc')
|
||||
self.check_not_exists('public/pool/main/p/pyspi/pyspi_0.6.1-1.3.diff.gz')
|
||||
self.check_not_exists('public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz')
|
||||
self.check_not_exists('public/pool/main/p/pyspi/pyspi-0.6.1-1.3.stripped.dsc')
|
||||
self.check_exists(
|
||||
'public/pool/main/b/boost-defaults/libboost-program-options-dev_1.49.0.1_i386.deb'
|
||||
)
|
||||
|
||||
|
||||
class JFrogPublish3Test(JFrogTest):
|
||||
"""
|
||||
publish to JFrog: publish drop performs cleanup
|
||||
"""
|
||||
|
||||
fixtureCmds = [
|
||||
'aptly repo create local1',
|
||||
'aptly repo create local2',
|
||||
'aptly repo add local1 ${files}/libboost-program-options-dev_1.49.0.1_i386.deb',
|
||||
'aptly repo add local2 ${files}',
|
||||
'aptly publish repo -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=sq1 local1 jfrog:test1:',
|
||||
'aptly publish repo -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=sq2 local2 jfrog:test1:',
|
||||
]
|
||||
runCmd = 'aptly publish drop sq2 jfrog:test1:'
|
||||
|
||||
def check(self):
|
||||
self.check_exists('public/dists/sq1')
|
||||
self.check_not_exists('public/dists/sq2')
|
||||
self.check_exists('public/pool/main/')
|
||||
|
||||
self.check_not_exists('public/pool/main/p/pyspi/pyspi_0.6.1-1.3.dsc')
|
||||
self.check_not_exists('public/pool/main/p/pyspi/pyspi_0.6.1-1.3.diff.gz')
|
||||
self.check_not_exists('public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz')
|
||||
self.check_not_exists('public/pool/main/p/pyspi/pyspi-0.6.1-1.3.stripped.dsc')
|
||||
self.check_exists(
|
||||
'public/pool/main/b/boost-defaults/libboost-program-options-dev_1.49.0.1_i386.deb'
|
||||
)
|
||||
Reference in New Issue
Block a user