Skip to content

feat: add command to create a test user for automated testing#329

Open
OliverTrautvetter wants to merge 12 commits intomainfrom
create_test_user
Open

feat: add command to create a test user for automated testing#329
OliverTrautvetter wants to merge 12 commits intomainfrom
create_test_user

Conversation

@OliverTrautvetter
Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/testuser package to generate credentials, hash them with Codesphere-compatible scheme, insert required DB records, and persist results as JSON.
  • Add oms create test-user command 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.

Comment thread internal/bootstrap/gcp/gcp.go Outdated
Comment thread internal/bootstrap/gcp/gcp_test.go
Comment thread cli/cmd/bootstrap_gcp.go Outdated
Comment thread cli/cmd/create_test_user.go
Comment thread internal/testuser/testuser.go Outdated
Comment thread internal/testuser/testuser.go Outdated
Comment thread internal/testuser/testuser.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/testuser/testuser.go Outdated
Comment thread internal/installer/node/node.go Outdated
Comment thread cli/cmd/bootstrap_gcp.go Outdated
Comment thread cli/cmd/create_test_user.go Outdated
Comment thread internal/testuser/hash.go Outdated
@OliverTrautvetter OliverTrautvetter marked this pull request as ready for review April 17, 2026 14:02
Copy link
Copy Markdown
Member

@joka134 joka134 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First comments, still debugging the command a little more tomorrow

Comment thread cli/cmd/bootstrap_gcp.go Outdated
Comment thread internal/testuser/testuser.go
Comment thread internal/testuser/testuser.go Outdated
Comment thread internal/testuser/testuser.go
Comment thread internal/testuser/testuser.go
Comment thread internal/testuser/hash.go Outdated
Copy link
Copy Markdown
Member

@joka134 joka134 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, much cleaner. Still some comments going into a similar direction

Comment thread cli/cmd/bootstrap_gcp.go Outdated
Comment thread internal/testuser/testuser.go Outdated
Comment thread internal/testuser/testuser.go Outdated
Comment thread internal/testuser/testuser.go Outdated
Comment thread cli/cmd/bootstrap_gcp.go Outdated
Comment thread internal/testuser/hash.go Outdated
Copy link
Copy Markdown
Member

@joka134 joka134 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is needed for test user creation?

}

// newWithDB creates a TestUserCreator with an already-opened DB.
func newWithDB(opts CreateTestUserOpts, db *sql.DB) *TestUserCreator {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? In the tests you can also just use &TestUserCreator{opts: opts, db: db}, right

Comment thread internal/testuser/hash.go

// 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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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.

3 participants