Skip to content

feat: enable acceptance tests with OrgManager role#922

Open
bonzofenix wants to merge 52 commits intocf-clifrom
fixed-acceptance-test-org
Open

feat: enable acceptance tests with OrgManager role#922
bonzofenix wants to merge 52 commits intocf-clifrom
fixed-acceptance-test-org

Conversation

@bonzofenix
Copy link
Contributor

@bonzofenix bonzofenix commented Jan 29, 2026

Summary

  • Enable acceptance tests to run with OrgManager and SpaceDeveloper roles instead of requiring CF admin privileges
  • Separate service access management into admin-only workflow step before tests run
  • Add CredHub integration for secure test user password management across CI runs

Changes

  • Add scripts/setup-acceptance-user.sh to create test users with OrgManager role and store credentials in CredHub
  • Add scripts/enable-service-access.sh to enable service access as admin before tests run
  • Update CI workflow .github/workflows/acceptance_tests_reusable.yaml to setup test user and enable service access before deployment
  • Add skip_service_access_management configuration option in acceptance/config/config.go to skip enable/disable operations during tests
  • Update test suite teardown logic in acceptance/*/suite_test.go to use CleanupInExistingOrg when using existing organization
  • Improve acceptance/helpers/cleanup.go to properly clean up all test spaces in existing organization mode
  • Add comprehensive documentation in CLAUDE.md for CI/CD workflows, OrgManager permissions, and debugging
  • Update acceptance/README.md with guidance for running tests with existing organizations and OrgManager role

Testing

  • CI acceptance tests pass with OrgManager user instead of admin
  • Service access is enabled before tests and persists throughout test execution
  • Test user credentials are securely managed via CredHub
  • Cleanup properly removes test spaces without deleting the existing organization
  • Documentation accurately reflects the new workflow

🤖 Generated with Claude Code

bonzofenix and others added 11 commits January 29, 2026 23:09
The tests were failing because newly created test spaces didn't have
service visibility, even though service access was enabled at the org
level. cf-test-helpers needs to explicitly enable service access for
each new test space it creates.

Changed SKIP_SERVICE_ACCESS_MANAGEMENT from true to false so that
cf-test-helpers will run 'cf enable-service-access' for each test
space, making the service visible to the OrgManager test user.
Change from 'cf enable-service-access <service> -o <org>' to
'cf enable-service-access <service>' to make the service visible
globally across all orgs and spaces.

This fixes the issue where new test spaces couldn't see the service
even though it was enabled for the organization. Global visibility
ensures all spaces (including newly created ones) can access the
service broker without requiring OrgManager to run enable-service-access
commands (which they don't have permission for).
Authenticate as the OrgManager user before trying to enable service
access globally. This will fail if OrgManager doesn't have sufficient
permissions, telling us whether this approach works in environments
without admin access during test execution.
- Removed service access logic from setup-acceptance-user.sh
- Created new enable-service-access.sh script
- Added workflow step to enable service access AFTER broker registration

This fixes the timing issue where we tried to enable service access
before the service broker was registered. Now:
1. Setup user (create user, assign OrgManager role)
2. Deploy and register service broker
3. Enable service access as OrgManager user
4. Run tests
Moved gh pr checks permission to global settings.

Co-Authored-By: Claude <noreply@anthropic.com>
Changed approach:
- Script now runs as admin (not OrgManager)
- Removed username/password parameters
- Admin enables service access globally after registering broker
- Tests run with OrgManager and SKIP_SERVICE_ACCESS_MANAGEMENT=true

This follows the constraint: admin used only during setup/deployment,
OrgManager used for test execution.
Set add_existing_user_to_existing_space=true to ensure cf-test-helpers
assigns SpaceDeveloper role to the OrgManager user in newly created
test spaces. OrgManagers can create spaces but don't automatically
get space-level roles needed to push apps.

Co-Authored-By: Claude <noreply@anthropic.com>
Merge setup scripts and simplify password handling:
- Update setup-acceptance-user.sh to retrieve password from CredHub (not passed as parameter)
- Add CREDHUB_TEST_USER_PASSWORD_PATH to vars.source.sh for consistent path reference
- Remove setup-test-user-and-env.sh (functionality merged into setup-acceptance-user.sh)
- Deploy job: Create user and store password in CredHub
- Acceptance tests job: Retrieve password from CredHub and set environment variables

This provides a clean separation:
- User setup happens in deploy job with admin credentials
- Test execution uses CredHub to retrieve password
- No environment variable exports in setup script (done in test job)

Co-Authored-By: Claude <noreply@anthropic.com>
@bonzofenix bonzofenix changed the title Running acceptance tests with orgManager and SpaceDeveloper feat: enable acceptance tests with OrgManager role Feb 2, 2026
bonzofenix and others added 10 commits February 2, 2026 17:42
Changes:
- Add autoscaler_test_user_password to secrets template interpolated from CredHub
- Read AUTOSCALER_TEST_PASSWORD using yq from secrets file instead of environment variable
- Remove admin fallback - AUTOSCALER_TEST_USER must be explicitly set
- Default EXISTING_USER to AUTOSCALER_TEST_USER
- Default EXISTING_USER_PASSWORD to AUTOSCALER_TEST_PASSWORD

This centralizes credential management in CredHub and removes hardcoded admin fallbacks.

Co-Authored-By: Claude <noreply@anthropic.com>
bonzofenix and others added 3 commits February 3, 2026 17:17
The setup script was storing the password at autoscaler_test_password
while the build script expected it at test_user_password, causing
deployment failures during credhub interpolation.

Co-Authored-By: Claude <noreply@anthropic.com>
@bonzofenix bonzofenix force-pushed the fixed-acceptance-test-org branch from 2dc3038 to 5b0f8e1 Compare February 3, 2026 17:24
bonzofenix and others added 6 commits February 3, 2026 18:29
…e.sh

The acceptance tests were failing because USE_EXISTING_ORGANIZATION was
defaulting to false when building the extension file. This caused
cf-test-helpers to attempt creating org quotas, which requires admin
privileges that the OrgManager test user doesn't have.

With this fix:
- USE_EXISTING_ORGANIZATION defaults to true
- EXISTING_ORGANIZATION defaults to AUTOSCALER_ORG
- Tests will use the existing org's quota instead of creating new ones
- OrgManager permissions are sufficient (only creates spaces, not quotas)

Root cause: build-extension-file.sh runs during deploy step before the
acceptance_tests job sets environment variables, so defaults matter.

Co-Authored-By: Claude <noreply@anthropic.com>
The acceptance tests were failing with user creation permission errors
because USE_EXISTING_USER was defaulting to false. This caused
cf-test-helpers to attempt creating new users, which requires admin
privileges that the OrgManager test user doesn't have.

With this fix:
- USE_EXISTING_USER defaults to true
- Tests will reuse the existing acceptance-test-user
- No user creation is attempted
- OrgManager permissions are sufficient

This is the second part of the OrgManager permissions fix. The first
part fixed USE_EXISTING_ORGANIZATION to skip quota creation.

Co-Authored-By: Claude <noreply@anthropic.com>
@bonzofenix bonzofenix changed the base branch from main to cf-cli February 9, 2026 09:33
@bonzofenix
Copy link
Contributor Author

Added Password Grant Support for Scaling Engine and Operator

This change enables the scaling engine and operator components to authenticate to Cloud Foundry using the acceptance test user credentials (username/password) instead of a UAA client.

Changes

CF Client (cf/config.go, cf/client.go):

  • Added GrantType, Username, and Password fields to Config struct
  • Added IsPasswordGrant() helper method
  • Modified NewCFClient() to support OAuth2 password grant flow
  • Extracted buildLoginForm() for cleaner code
  • Split validation into validateAPI(), validatePasswordGrant(), and validateClientCredentials()

Deployment Configuration (scripts/build-extension-file.sh):

  • Scaling engine now uses password grant with ${AUTOSCALER_TEST_USER} credentials
  • Operator also uses password grant with the same user
  • Added new config fields: grant_type, username, password

Tests (cf/config_test.go, cf/client_test.go):

  • Added test cases for password grant validation
  • Added test for password grant login flow

Backward Compatibility

  • GrantType defaults to client_credentials if not specified
  • Existing configurations continue to work unchanged

@bonzofenix bonzofenix force-pushed the fixed-acceptance-test-org branch from cde38d3 to eab0a1f Compare February 9, 2026 10:48
bonzofenix and others added 3 commits February 9, 2026 12:04
Integrates the go-cfclient refactoring with password grant support:
- CF client now uses go-cfclient library wrapper
- Added password grant support via config.UserPassword option
- Removed old custom CF client implementation
- Regenerated fakes for new interface signatures

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for password grant with explicit client_id preservation
- Add test for CFClientWrapper creation with password grant

Co-Authored-By: Claude <noreply@anthropic.com>
…nager

- Extract security group setup from mta-deploy.sh into separate
  scripts/set-security-group.sh with dedicated `make set-security-group` target
- Remove metricsforwarder/Makefile (security group logic moved to new script)
- Security group is now space-scoped instead of global
- Rename cf_login to cf_admin_login to allow for future org manager login
- Rename AUTOSCALER_TEST_USER to AUTOSCALER_ORG_MANAGER_USER
- Rename AUTOSCALER_TEST_PASSWORD to AUTOSCALER_ORG_MANAGER_PASSWORD
- Simplify setup-acceptance-user.sh to delete and recreate user for idempotency

Co-Authored-By: Claude <noreply@anthropic.com>
@bonzofenix
Copy link
Contributor Author

Refactoring: Security Group Setup & User Renaming

Changes in this commit:

Security Group Extraction:

  • Extracted security group setup from mta-deploy.sh into a standalone scripts/set-security-group.sh
  • Added new make set-security-group target for independent execution
  • Security group is now space-scoped instead of global (uses --space flag)
  • Removed metricsforwarder/Makefile (logic consolidated into new script)

CF Login Refactoring:

  • Renamed cf_logincf_admin_login to clarify it uses admin credentials
  • This allows adding a separate cf_login function later for org manager authentication

User Variable Renaming:

  • AUTOSCALER_TEST_USERAUTOSCALER_ORG_MANAGER_USER
  • AUTOSCALER_TEST_PASSWORDAUTOSCALER_ORG_MANAGER_PASSWORD
  • CREDHUB_TEST_USER_PASSWORD_PATHCREDHUB_ORG_MANAGER_PASSWORD_PATH
  • Default username: acceptance-test-userorg-manager-user

Simplified User Setup:

  • setup-acceptance-user.sh now deletes and recreates the user for idempotency

…tion

- Add cf_login function for org manager authentication (separate from cf_admin_login)
- Setup org manager user with SpaceManager + SpaceDeveloper roles for MTA deployments
- Register service broker as space-scoped (allows non-admin registration)
- Rename setup-acceptance-user to setup-org-manager-user
- Rename deploy-register-cf to register-broker
- Rename cf-login target to cf-admin-login
- Add deploying user message to mta-deploy.sh
- Simplify scripts: remove unused code, fix indentation, remove unnecessary pushd/popd

Co-Authored-By: Claude <noreply@anthropic.com>
@bonzofenix
Copy link
Contributor Author

Changes

  • Add cf_login function for org manager authentication
  • Rename cf_admin_login and make cf-admin-login target
  • Rename setup-acceptance-user.sh to setup-org-manager-user.sh
  • Add SpaceManager + SpaceDeveloper roles to org manager user
  • Register service broker as space-scoped (--space-scoped)
  • Rename deploy-register-cf to register-broker
  • Simplify scripts (remove unused code, fix indentation)

Commit: 925c619

Enable password grant OAuth2 flow for log-cache access in the event
generator. This allows authentication using org manager credentials
instead of requiring a dedicated UAA client with client_credentials.

- Add GrantType, Username, Password fields to UAACreds model
- Add IsPasswordGrant() method to detect password grant configuration
- Update fetcher factory to use WithOauth2HTTPUser() for password grants
- Configure deployment scripts to use org manager credentials

Co-Authored-By: Claude <noreply@anthropic.com>
@bonzofenix
Copy link
Contributor Author

Event Generator Password Grant Support

This commit adds password grant authentication for the event generator's log-cache access.

Changes

  • models/uaa_creds.go: Added GrantType, Username, Password fields and IsPasswordGrant() method
  • eventgenerator/metric/fetcher_factory.go: Updated to use logcache.WithOauth2HTTPUser() when password grant is configured
  • eventgenerator/metric/fetcher_factory_test.go: Added test case for password grant authentication
  • scripts/build-extension-file.sh: Configured to use org manager credentials with password grant

Why Password Grant?

The event generator needs to access log-cache for metrics. Instead of requiring a dedicated UAA client with client_credentials grant, this change allows using the org manager user credentials with the password grant type. This simplifies deployment by reusing existing org manager credentials.

Testing

All password grant tests pass. The fetcher factory correctly configures the OAuth2 HTTP client with user credentials when grant_type: password is set.

bonzofenix and others added 5 commits February 10, 2026 23:26
The go-log-cache library's OAuth2 client sends credentials in the
request body, but CF's "cf" UAA client requires Basic auth header.
This custom CFOauth2HTTPClient:

- Sends client_id:client_secret via Basic auth header
- Uses password grant with username/password in form body
- Handles 401 responses with automatic token refresh
- Passes all acceptance tests

Co-Authored-By: Claude <noreply@anthropic.com>
Add unit tests for the custom OAuth2 HTTP client that uses Basic auth
for token requests (required by CF's "cf" UAA client). Tests cover:

- Bearer token injection for authenticated requests
- Token reuse across multiple requests
- Token refresh on 401 Unauthorized responses
- Thread-safe concurrent request handling
- Basic auth header format for client credentials
- Error handling for token endpoint failures
- SSL validation configuration
- Malformed token response handling

These tests ensure the OAuth2 client properly authenticates with
CloudFoundry's UAA and handles token lifecycle management correctly.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
The 60-second timeout was insufficient in CI environments, causing
broker deletion to fail with "cannot remove brokers that have
associated service instances" errors. Increasing to 180 seconds
(36 polling attempts at 5s intervals) gives CF adequate time to
complete asynchronous service instance deletions during cleanup.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@bonzofenix bonzofenix force-pushed the fixed-acceptance-test-org branch from f7b5040 to 4ad8b82 Compare February 13, 2026 15:17
The workflow was calling cf_login which doesn't exist in scripts/common.sh.
Changed to cf_org_manager_login which is the correct function name.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
4.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant