feat: add command to create a test user for automated testing#329
feat: add command to create a test user for automated testing#329OliverTrautvetter wants to merge 12 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new OMS CLI capability to create a Codesphere “test user” (password + API token) directly in PostgreSQL for automated smoke testing, and wires it into docs and (optionally) the GCP bootstrap flow.
Changes:
- Introduce
internal/testuserpackage to generate credentials, hash them with Codesphere-compatible scheme, insert required DB records, and persist results as JSON. - Add
oms create test-usercommand group/command and corresponding CLI docs. - Adjust GCP bootstrap package download invocation and bump/add Go dependencies (sqlmock, lib/pq).
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
internal/testuser/testuser.go |
Implements test user creation, DB inserts, result logging/persistence |
internal/testuser/hash.go |
Adds hashing helpers for password/API token |
internal/testuser/hash_test.go |
Unit tests for hashing |
internal/testuser/testuser_test.go |
Unit tests for token generation, file writing, and DB logic via sqlmock |
internal/testuser/testuser_suite_test.go |
Ginkgo suite bootstrap for new package |
cli/cmd/create.go |
Adds oms create command group |
cli/cmd/create_test_user.go |
Adds oms create test-user cobra command |
cli/cmd/root.go |
Registers the new create command group |
cli/cmd/bootstrap_gcp.go |
Adds optional --create-test-user behavior post-bootstrap |
internal/bootstrap/gcp/gcp.go |
Changes jumpbox download command to include OMS portal env vars |
internal/bootstrap/gcp/gcp_test.go |
Updates expected download command strings in tests |
docs/oms_create.md / docs/oms_create_test-user.md |
New CLI documentation pages |
docs/oms.md / docs/README.md |
Adds oms create to command index |
docs/oms_beta_bootstrap-gcp.md |
Documents --create-test-user flag |
go.mod / go.sum |
Adds go-sqlmock, bumps github.com/lib/pq |
NOTICE / internal/tmpl/NOTICE |
Updates NOTICE entries for github.com/lib/pq version bump |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 20 out of 21 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
30b3192 to
8b27054
Compare
joka134
left a comment
There was a problem hiding this comment.
First comments, still debugging the command a little more tomorrow
Signed-off-by: OliverTrautvetter <66372584+OliverTrautvetter@users.noreply.github.com>
joka134
left a comment
There was a problem hiding this comment.
Nice, much cleaner. Still some comments going into a similar direction
Signed-off-by: OliverTrautvetter <66372584+OliverTrautvetter@users.noreply.github.com>
…d/oms into create_test_user
joka134
left a comment
There was a problem hiding this comment.
some small things + the one thing we discussed
| _ = session.Setenv("OMS_PORTAL_API", os.Getenv("OMS_PORTAL_API")) | ||
| _ = agent.RequestAgentForwarding(session) // Best effort, ignore errors | ||
|
|
||
| var stderrBuf bytes.Buffer |
There was a problem hiding this comment.
| var stderrBuf bytes.Buffer | |
| var stderrBuf bytes.Buffer | |
| session.Stderr = &stderrBuf |
and drop the else statement
| defer util.IgnoreError(session.Close) | ||
|
|
||
| _ = session.Setenv("OMS_PORTAL_API_KEY", os.Getenv("OMS_PORTAL_API_KEY")) | ||
| _ = session.Setenv("OMS_PORTAL_API", os.Getenv("OMS_PORTAL_API")) |
There was a problem hiding this comment.
Why is needed for test user creation?
| } | ||
|
|
||
| // newWithDB creates a TestUserCreator with an already-opened DB. | ||
| func newWithDB(opts CreateTestUserOpts, db *sql.DB) *TestUserCreator { |
There was a problem hiding this comment.
Do we need this? In the tests you can also just use &TestUserCreator{opts: opts, db: db}, right
|
|
||
| // HashPassword hashes a password using Codesphere's double-SHA256 scheme with salts. | ||
| // The salts are read from environment variables OMS_CS_SALT_1 and OMS_CS_SALT_2. | ||
| func HashPassword(password string) (string, error) { |
There was a problem hiding this comment.
Maybe I came to a new conclusion to just keep out the salts of oms and create a password hash manually, that is provided via env. That means the test user always gets the same password, which is fine as signup is usually open for test instances. And now one will be forced to copy/paste salts to local environments 😆
The password (+ hash for local development) will be stored in 1password
Clickup