Skip to content

Commit

Permalink
fix service account identity (#1591)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabriciaDinizRH authored Jan 17, 2024
1 parent 746f32a commit 9499139
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 2 additions & 3 deletions app/auth/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from app.logging import get_logger
from app.logging import threadctx
from app.validators import verify_uuid_format


__all__ = ["Identity", "from_auth_header", "from_bearer_token"]
Expand Down Expand Up @@ -165,8 +164,8 @@ class SystemIdentitySchema(IdentityBaseSchema):


class ServiceAccountInfoIdentitySchema(IdentityBaseSchema):
client_id = m.fields.Str(required=True, validate=verify_uuid_format)
username = m.fields.Str(required=True, validate=m.validate.Length(min=1))
client_id = m.fields.Str(required=True)
username = m.fields.Str(required=True)


class ServiceAccountIdentitySchema(IdentityBaseSchema):
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"auth_type": "jwt-auth",
"internal": {"auth_time": 500, "cross_access": False, "org_id": "456"},
"service_account": {
"client_id": "b9757340-f839-4541-9af6-f7535edf08db",
"username": "service-account-b9757340-f839-4541-9af6-f7535edf08db",
"client_id": "b69eaf9e-e6a6-4f9e-805e-02987daddfbd",
"username": "service-account-b69eaf9e-e6a6-4f9e-805e-02987daddfbd",
},
"type": "ServiceAccount",
}
Expand Down
9 changes: 8 additions & 1 deletion tests/test_identity_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_service_account_identity_missing_required(required):
# Test blank values
bad_identity = copy.deepcopy(SERVICE_ACCOUNT_IDENTITY)
assert "service_account" in bad_identity
bad_identity["service_account"][required] = ""
bad_identity["service_account"][required] = 51549684651
with pytest.raises(ValueError):
identity_test_common(bad_identity)

Expand All @@ -131,6 +131,13 @@ def test_service_account_identity_missing_required(required):
with pytest.raises(ValueError):
identity_test_common(bad_identity)

# Test missing service_account
bad_identity = copy.deepcopy(SERVICE_ACCOUNT_IDENTITY)
assert "service_account" in bad_identity
bad_identity.pop("service_account", None)
with pytest.raises(ValueError):
identity_test_common(bad_identity)


@pytest.mark.parametrize(
"test_field,bad_value",
Expand Down

0 comments on commit 9499139

Please sign in to comment.