コード例 #1
0
ファイル: test_validate_torrent.py プロジェクト: zhill/quay
def test_validate_torrent(unvalidated_config, expected, app):
    announcer_hit = [False]

    @urlmatch(netloc=r"faketorrent", path="/announce")
    def handler(url, request):
        announcer_hit[0] = True
        return {"status_code": 200, "content": ""}

    with HTTMock(handler):
        validator = BittorrentValidator()
        if expected is not None:
            with pytest.raises(expected):
                config = ValidatorContext(unvalidated_config,
                                          instance_keys=instance_keys)
                config.http_client = build_requests_session()

                validator.validate(config)
            assert not announcer_hit[0]
        else:
            config = ValidatorContext(unvalidated_config,
                                      instance_keys=instance_keys)
            config.http_client = build_requests_session()

            validator.validate(config)
            assert announcer_hit[0]
コード例 #2
0
def test_validate_oidc_login(app):
    url_hit = [False]

    @urlmatch(netloc=r"someserver", path=r"/\.well-known/openid-configuration")
    def handler(_, __):
        url_hit[0] = True
        data = {
            "token_endpoint": "foobar",
        }
        return {"status_code": 200, "content": json.dumps(data)}

    with HTTMock(handler):
        validator = OIDCLoginValidator()
        unvalidated_config = ValidatorContext({
            "SOMETHING_LOGIN_CONFIG": {
                "CLIENT_ID": "foo",
                "CLIENT_SECRET": "bar",
                "OIDC_SERVER": "http://someserver",
                "DEBUGGING": True,  # Allows for HTTP.
            },
        })
        unvalidated_config.http_client = build_requests_session()

        validator.validate(unvalidated_config)

    assert url_hit[0]
コード例 #3
0
def test_validate_google_login(app):
    url_hit = [False]

    @urlmatch(netloc=r"www.googleapis.com", path="/oauth2/v3/token")
    def handler(_, __):
        url_hit[0] = True
        return {"status_code": 200, "content": ""}

    validator = GoogleLoginValidator()

    with HTTMock(handler):
        unvalidated_config = ValidatorContext(
            {
                "GOOGLE_LOGIN_CONFIG": {
                    "CLIENT_ID": "foo",
                    "CLIENT_SECRET": "bar",
                },
            }
        )

        unvalidated_config.http_client = build_requests_session()

        validator.validate(unvalidated_config)

    assert url_hit[0]
コード例 #4
0
def test_validate_oidc_login(app):
  url_hit = [False]
  @urlmatch(netloc=r'someserver', path=r'/\.well-known/openid-configuration')
  def handler(_, __):
    url_hit[0] = True
    data = {
      'token_endpoint': 'foobar',
    }
    return {'status_code': 200, 'content': json.dumps(data)}

  with HTTMock(handler):
    validator = OIDCLoginValidator()
    unvalidated_config = ValidatorContext({
      'SOMETHING_LOGIN_CONFIG': {
        'CLIENT_ID': 'foo',
        'CLIENT_SECRET': 'bar',
        'OIDC_SERVER': 'http://someserver',
        'DEBUGGING': True, # Allows for HTTP.
      },
    })
    unvalidated_config.http_client = build_requests_session()

    validator.validate(unvalidated_config)

  assert url_hit[0]
コード例 #5
0
ファイル: test_validate_github.py プロジェクト: xzwupeng/quay
def test_validate_github(github_validator, app):
    url_hit = [False, False]

    @urlmatch(netloc=r'somehost')
    def handler(url, request):
        url_hit[0] = True
        return {
            'status_code': 200,
            'content': '',
            'headers': {
                'X-GitHub-Request-Id': 'foo'
            }
        }

    @urlmatch(netloc=r'somehost', path=r'/api/v3/applications/foo/tokens/foo')
    def app_handler(url, request):
        url_hit[1] = True
        return {
            'status_code': 404,
            'content': '',
            'headers': {
                'X-GitHub-Request-Id': 'foo'
            }
        }

    with HTTMock(app_handler, handler):
        unvalidated_config = ValidatorContext({
            github_validator.config_key: {
                'GITHUB_ENDPOINT': 'http://somehost',
                'CLIENT_ID': 'foo',
                'CLIENT_SECRET': 'bar',
            },
        })

        unvalidated_config.http_client = build_requests_session()
        github_validator.validate(unvalidated_config)

    assert url_hit[0]
    assert url_hit[1]
コード例 #6
0
def test_validate_github(github_validator, app):
    url_hit = [False, False]

    @urlmatch(netloc=r"somehost")
    def handler(url, request):
        url_hit[0] = True
        return {
            "status_code": 200,
            "content": "",
            "headers": {
                "X-GitHub-Request-Id": "foo"
            }
        }

    @urlmatch(netloc=r"somehost", path=r"/api/v3/applications/foo/tokens/foo")
    def app_handler(url, request):
        url_hit[1] = True
        return {
            "status_code": 404,
            "content": "",
            "headers": {
                "X-GitHub-Request-Id": "foo"
            }
        }

    with HTTMock(app_handler, handler):
        unvalidated_config = ValidatorContext({
            github_validator.config_key: {
                "GITHUB_ENDPOINT": "http://somehost",
                "CLIENT_ID": "foo",
                "CLIENT_SECRET": "bar",
            },
        })

        unvalidated_config.http_client = build_requests_session()
        github_validator.validate(unvalidated_config)

    assert url_hit[0]
    assert url_hit[1]
コード例 #7
0
def test_validate_google_login(app):
    url_hit = [False]

    @urlmatch(netloc=r'www.googleapis.com', path='/oauth2/v3/token')
    def handler(_, __):
        url_hit[0] = True
        return {'status_code': 200, 'content': ''}

    validator = GoogleLoginValidator()

    with HTTMock(handler):
        unvalidated_config = ValidatorContext({
            'GOOGLE_LOGIN_CONFIG': {
                'CLIENT_ID': 'foo',
                'CLIENT_SECRET': 'bar',
            },
        })

        unvalidated_config.http_client = build_requests_session()

        validator.validate(unvalidated_config)

    assert url_hit[0]
コード例 #8
0
def test_validated_jwt(username, password, expected_exception, app):
    with fake_jwt() as jwt_auth:
        config = {}
        config['AUTHENTICATION_TYPE'] = 'JWT'
        config['JWT_AUTH_ISSUER'] = jwt_auth.issuer
        config['JWT_VERIFY_ENDPOINT'] = jwt_auth.verify_url
        config['JWT_QUERY_ENDPOINT'] = jwt_auth.query_url
        config['JWT_GETUSER_ENDPOINT'] = jwt_auth.getuser_url

        unvalidated_config = ValidatorContext(config)
        unvalidated_config.user = AttrDict(dict(username=username))
        unvalidated_config.user_password = password
        unvalidated_config.config_provider = config_provider

        unvalidated_config.http_client = build_requests_session()

        if expected_exception is not None:
            with pytest.raises(ConfigValidationException):
                JWTAuthValidator.validate(
                    unvalidated_config,
                    public_key_path=jwt_auth.public_key_path)
        else:
            JWTAuthValidator.validate(unvalidated_config,
                                      public_key_path=jwt_auth.public_key_path)