Add support for pull credentials on builds and build triggers
This commit is contained in:
parent
1fc3c922a9
commit
2006917e03
17 changed files with 355 additions and 37 deletions
|
@ -982,6 +982,33 @@ class TestRequestRepoBuild(ApiTestCase):
|
|||
|
||||
assert len(json['builds']) > 0
|
||||
|
||||
def test_requestrepobuild_with_credentials(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
# Ensure where not yet building.
|
||||
json = self.getJsonResponse(RepositoryBuildList,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
||||
|
||||
assert len(json['builds']) == 0
|
||||
|
||||
# Request a (fake) build.
|
||||
pull_creds = {
|
||||
'username': 'foo',
|
||||
'password': 'bar',
|
||||
'registry': 'baz'
|
||||
}
|
||||
self.postResponse(RepositoryBuildList,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
||||
data=dict(file_id='foobarbaz', pull_credentials=pull_creds),
|
||||
expected_code=201)
|
||||
|
||||
# Check for the build.
|
||||
json = self.getJsonResponse(RepositoryBuildList,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/building'))
|
||||
|
||||
assert len(json['builds']) > 0
|
||||
|
||||
|
||||
|
||||
class TestWebhooks(ApiTestCase):
|
||||
def test_webhooks(self):
|
||||
|
@ -1642,7 +1669,7 @@ class TestBuildTriggers(ApiTestCase):
|
|||
trigger_config = {}
|
||||
activate_json = self.postJsonResponse(BuildTriggerActivate,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
||||
data=trigger_config)
|
||||
data={'config': trigger_config})
|
||||
|
||||
self.assertEquals(True, activate_json['is_active'])
|
||||
|
||||
|
@ -1654,7 +1681,7 @@ class TestBuildTriggers(ApiTestCase):
|
|||
# Make sure we cannot activate again.
|
||||
self.postResponse(BuildTriggerActivate,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
||||
data=trigger_config,
|
||||
data={'config': trigger_config},
|
||||
expected_code=400)
|
||||
|
||||
# Start a manual build.
|
||||
|
@ -1667,6 +1694,69 @@ class TestBuildTriggers(ApiTestCase):
|
|||
self.assertEquals(['bar'], start_json['job_config']['docker_tags'])
|
||||
|
||||
|
||||
def test_invalid_robot_account(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
database.BuildTriggerService.create(name='fakeservice')
|
||||
|
||||
# Add a new fake trigger.
|
||||
repo = model.get_repository(ADMIN_ACCESS_USER, 'simple')
|
||||
user = model.get_user(ADMIN_ACCESS_USER)
|
||||
trigger = model.create_build_trigger(repo, 'fakeservice', 'sometoken', user)
|
||||
|
||||
# Try to activate it with an invalid robot account.
|
||||
trigger_config = {}
|
||||
activate_json = self.postJsonResponse(BuildTriggerActivate,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
||||
data={'config': trigger_config, 'pull_robot': 'someinvalidrobot'},
|
||||
expected_code=404)
|
||||
|
||||
def test_unauthorized_robot_account(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
database.BuildTriggerService.create(name='fakeservice')
|
||||
|
||||
# Add a new fake trigger.
|
||||
repo = model.get_repository(ADMIN_ACCESS_USER, 'simple')
|
||||
user = model.get_user(ADMIN_ACCESS_USER)
|
||||
trigger = model.create_build_trigger(repo, 'fakeservice', 'sometoken', user)
|
||||
|
||||
# Try to activate it with a robot account in the wrong namespace.
|
||||
trigger_config = {}
|
||||
activate_json = self.postJsonResponse(BuildTriggerActivate,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
||||
data={'config': trigger_config, 'pull_robot': 'freshuser+anotherrobot'},
|
||||
expected_code=403)
|
||||
|
||||
def test_robot_account(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
database.BuildTriggerService.create(name='fakeservice')
|
||||
|
||||
# Add a new fake trigger.
|
||||
repo = model.get_repository(ADMIN_ACCESS_USER, 'simple')
|
||||
user = model.get_user(ADMIN_ACCESS_USER)
|
||||
trigger = model.create_build_trigger(repo, 'fakeservice', 'sometoken', user)
|
||||
|
||||
# Try to activate it with a robot account.
|
||||
trigger_config = {}
|
||||
activate_json = self.postJsonResponse(BuildTriggerActivate,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
||||
data={'config': trigger_config, 'pull_robot': ADMIN_ACCESS_USER + '+dtrobot'})
|
||||
|
||||
# Verify that the robot was saved.
|
||||
self.assertEquals(True, activate_json['is_active'])
|
||||
self.assertEquals(ADMIN_ACCESS_USER + '+dtrobot', activate_json['pull_user']['name'])
|
||||
|
||||
# Start a manual build.
|
||||
start_json = self.postJsonResponse(ActivateBuildTrigger,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
||||
expected_code=201)
|
||||
|
||||
assert 'id' in start_json
|
||||
self.assertEquals("build-name", start_json['display_name'])
|
||||
self.assertEquals(['bar'], start_json['job_config']['docker_tags'])
|
||||
|
||||
|
||||
class TestUserAuthorizations(ApiTestCase):
|
||||
def test_list_get_delete_user_authorizations(self):
|
||||
|
|
Reference in a new issue