a6486b7823
Gitlab config validator currently requires the gitlab endpoint to be specified, even though we support leaving it unspecified for non-enterprise installs. Fix the validator to allow this case.
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import json
|
|
import pytest
|
|
|
|
from httmock import urlmatch, HTTMock
|
|
|
|
from util.config.validators import ConfigValidationException
|
|
from util.config.validators.validate_gitlab_trigger import GitLabTriggerValidator
|
|
|
|
@pytest.mark.parametrize('unvalidated_config', [
|
|
({}),
|
|
({'GITLAB_TRIGGER_CONFIG': {'GITLAB_ENDPOINT': 'foo'}}),
|
|
({'GITLAB_TRIGGER_CONFIG': {'GITLAB_ENDPOINT': 'http://someendpoint', 'CLIENT_ID': 'foo'}}),
|
|
({'GITLAB_TRIGGER_CONFIG': {'GITLAB_ENDPOINT': 'http://someendpoint', 'CLIENT_SECRET': 'foo'}}),
|
|
])
|
|
def test_validate_invalid_gitlab_trigger_config(unvalidated_config):
|
|
validator = GitLabTriggerValidator()
|
|
|
|
with pytest.raises(ConfigValidationException):
|
|
validator.validate(unvalidated_config, None, None)
|
|
|
|
def test_validate_gitlab_enterprise_trigger():
|
|
url_hit = [False]
|
|
|
|
@urlmatch(netloc=r'somegitlab', path='/oauth/token')
|
|
def handler(_, __):
|
|
url_hit[0] = True
|
|
return {'status_code': 400, 'content': json.dumps({'error': 'invalid code'})}
|
|
|
|
with HTTMock(handler):
|
|
validator = GitLabTriggerValidator()
|
|
validator.validate({
|
|
'GITLAB_TRIGGER_CONFIG': {
|
|
'GITLAB_ENDPOINT': 'http://somegitlab',
|
|
'CLIENT_ID': 'foo',
|
|
'CLIENT_SECRET': 'bar',
|
|
},
|
|
}, None, None)
|
|
|
|
assert url_hit[0]
|