def wrapper(namespace_name, repo_name, *args, **kwargs): response = f(namespace_name, repo_name, *args, **kwargs) # Setting session namespace and repository session["namespace"] = namespace_name session["repository"] = repo_name # We run our index and registry on the same hosts for now registry_server = urlparse.urlparse(request.url).netloc response.headers["X-Docker-Endpoints"] = registry_server has_token_request = request.headers.get("X-Docker-Token", "") force_grant = add_grant_for_status == response.status_code if has_token_request or force_grant: grants = [] if scope == GrantType.READ_REPOSITORY: if force_grant or ReadRepositoryPermission(namespace_name, repo_name).can(): grants.append(repository_read_grant(namespace_name, repo_name)) elif scope == GrantType.WRITE_REPOSITORY: if force_grant or ModifyRepositoryPermission(namespace_name, repo_name).can(): grants.append(repository_write_grant(namespace_name, repo_name)) # Generate a signed token for the user (if any) and the grants (if any) if grants or get_authenticated_user(): user_context = get_authenticated_user() and get_authenticated_user().username signature = generate_signed_token(grants, user_context) response.headers["WWW-Authenticate"] = signature response.headers["X-Docker-Token"] = signature return response
def test_valid_grant(): header = 'token ' + generate_signed_token({'a': 'b'}, {'c': 'd'}) expected = ValidateResult(AuthKind.signed_grant, signed_data={ 'grants': { 'a': 'b', }, 'user_context': { 'c': 'd' }, }) assert validate_signed_grant(header) == expected
def test_valid_grant(): header = "token " + generate_signed_token({"a": "b"}, {"c": "d"}) expected = ValidateResult( AuthKind.signed_grant, signed_data={ "grants": { "a": "b", }, "user_context": {"c": "d"}, }, ) assert validate_signed_grant(header) == expected