Skip to content

fix: sonarqube findings, deprecations, ownership enforcement, test fi…#10

Merged
Maneesh-Relanto merged 1 commit intomainfrom
fix/sonarqube-and-test-fixes
Feb 23, 2026
Merged

fix: sonarqube findings, deprecations, ownership enforcement, test fi…#10
Maneesh-Relanto merged 1 commit intomainfrom
fix/sonarqube-and-test-fixes

Conversation

@Maneesh-Relanto
Copy link
Owner

…eld names

SonarQube / code quality fixes:

  • src/rbac/storage/sqlalchemy_adapter.py: extract _FK_ROLES_ID constant for duplicate 'rbac_roles.id' literal; rename _Session -> _session_factory to resolve naming clash with _session() method
  • src/rbac/core/models/init.py: replace datetime.utcnow with _utcnow() helper returning timezone-aware datetime.now(timezone.utc)
  • test-apps/02-flask-blog-api/app.py: refactor into Flask Blueprints to reduce cognitive complexity (67 -> minimal); fix utcnow; add perm_comment_delete to reader role
  • test-apps/02-flask-blog-api/decorators.py: extract _fetch_owned_resource, _build_permission_context, forbidden_response helpers; add ownership enforcement via OWNERSHIP_OVERRIDE_ROLES; add MSG* constants
  • test-apps/02-flask-blog-api/models.py: fix utcnow deprecation
  • test-apps/02-flask-blog-api/storage.py: fix utcnow deprecation (5 places)
  • test-apps/02-flask-blog-api/test_api.py: fix test_update_others_post_as_author to target correct post (/posts/4 not /posts/1)
  • test-apps/03-fastapi-blog-api/dependencies.py: extract _resolve_resource, _build_context, _raise_forbidden; add OWNERSHIP_OVERRIDE_ROLES enforcement
  • test-apps/03-fastapi-blog-api/seed_data.py: extract title constants; add NOSONAR on demo passwords; remove unnecessary f-string
  • test-apps/03-fastapi-blog-api/test_api.py: remove unused variable; add NOSONAR on hardcoded test credentials

Pre-existing test model field-name mismatches fixed:

  • tests/conftest.py: username -> name, metadata -> attributes, fix Permission fields (resource -> resource_type, drop domain)
  • tests/test_models.py: same field-name fixes + assertion updates
  • tests/test_storage.py: username -> name
  • tests/integration/test_complete_workflows.py: username -> name, metadata -> attributes, Permission resource=obj -> resource_type=obj.type
  • tests/property/test_authorization_invariants.py: username -> name, Permission resource=obj -> resource_type=obj.type

Test results after fixes:

  • test-apps/02-flask-blog-api: 34/34 passing
  • test-apps/03-fastapi-blog-api: 39/39 passing
  • tests/test_sqlalchemy_storage.py: 50/50 passing

…eld names

SonarQube / code quality fixes:
- src/rbac/storage/sqlalchemy_adapter.py: extract _FK_ROLES_ID constant for
  duplicate 'rbac_roles.id' literal; rename _Session -> _session_factory to
  resolve naming clash with _session() method
- src/rbac/core/models/__init__.py: replace datetime.utcnow with _utcnow()
  helper returning timezone-aware datetime.now(timezone.utc)
- test-apps/02-flask-blog-api/app.py: refactor into Flask Blueprints to reduce
  cognitive complexity (67 -> minimal); fix utcnow; add perm_comment_delete to
  reader role
- test-apps/02-flask-blog-api/decorators.py: extract _fetch_owned_resource,
  _build_permission_context, _forbidden_response helpers; add ownership
  enforcement via OWNERSHIP_OVERRIDE_ROLES; add MSG_* constants
- test-apps/02-flask-blog-api/models.py: fix utcnow deprecation
- test-apps/02-flask-blog-api/storage.py: fix utcnow deprecation (5 places)
- test-apps/02-flask-blog-api/test_api.py: fix test_update_others_post_as_author
  to target correct post (/posts/4 not /posts/1)
- test-apps/03-fastapi-blog-api/dependencies.py: extract _resolve_resource,
  _build_context, _raise_forbidden; add OWNERSHIP_OVERRIDE_ROLES enforcement
- test-apps/03-fastapi-blog-api/seed_data.py: extract title constants; add
  NOSONAR on demo passwords; remove unnecessary f-string
- test-apps/03-fastapi-blog-api/test_api.py: remove unused variable; add
  NOSONAR on hardcoded test credentials

Pre-existing test model field-name mismatches fixed:
- tests/conftest.py: username -> name, metadata -> attributes, fix Permission
  fields (resource -> resource_type, drop domain)
- tests/test_models.py: same field-name fixes + assertion updates
- tests/test_storage.py: username -> name
- tests/integration/test_complete_workflows.py: username -> name,
  metadata -> attributes, Permission resource=obj -> resource_type=obj.type
- tests/property/test_authorization_invariants.py: username -> name,
  Permission resource=obj -> resource_type=obj.type

Test results after fixes:
- test-apps/02-flask-blog-api: 34/34 passing
- test-apps/03-fastapi-blog-api: 39/39 passing
- tests/test_sqlalchemy_storage.py: 50/50 passing
@Maneesh-Relanto Maneesh-Relanto merged commit 2111cf0 into main Feb 23, 2026
4 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant