Skip to content

Commit d21db0d

Browse files
authored
fix(jfrog-oauth): fail when access_token is empty (#574)
## Summary Fixes #72 - The `jfrog-oauth` module now fails with a clear error message when the JFrog access token is empty, instead of silently creating configurations with empty tokens. ## Changes ### 1. Added Precondition Validation (`main.tf`) ```hcl lifecycle { precondition { condition = data.coder_external_auth.jfrog.access_token != "" error_message = "JFrog access token is empty. Please authenticate with JFrog using external auth." } } ``` This ensures the module fails at **plan time** with a clear error when users haven't authenticated via external auth. ### 2. Replaced `main.test.ts` with `jfrog-oauth.tftest.hcl` **Why we removed the TypeScript tests:** The TypeScript tests used `runTerraformApply()` which runs `terraform apply` directly. This approach **cannot mock data sources** like `coder_external_auth`. The Coder provider returns empty strings for tokens by default when running outside a real Coder workspace. With our new precondition, the TypeScript tests would always fail because: 1. `terraform apply` runs → empty `access_token` from mock provider 2. Precondition check fails → "JFrog access token is empty" 3. Test fails before any assertions run **The solution:** Terraform's native `.tftest.hcl` format supports `override_data` blocks that can properly mock data sources: ```hcl override_data { target = data.coder_external_auth.jfrog values = { access_token = "valid-token-value" # or "" to test failure } } ``` ### 3. Comprehensive Test Coverage The new `jfrog-oauth.tftest.hcl` includes **12 tests** (up from 7): | Test | What it validates | |------|------------------| | `test_required_vars` | Basic module works with required variables | | `test_empty_access_token_fails` | **NEW:** Precondition rejects empty tokens | | `test_valid_access_token_succeeds` | Module works with valid token | | `test_jfrog_url_validation` | **NEW:** URL must start with http(s):// | | `test_username_field_validation` | **NEW:** Must be "email" or "username" | | `test_with_npm_package_manager` | NPM config with scoped repos (script content) | | `test_configure_code_server` | **NEW:** IDE env vars created when enabled | | `test_go_proxy_env` | GOPROXY env value with multiple repos | | `test_pypi_package_manager` | pip.conf with extra-index-url | | `test_docker_package_manager` | register_docker commands for all repos | | `test_conda_package_manager` | .condarc channels configuration | | `test_maven_package_manager` | settings.xml with servers and repos | All package manager tests use `strcontains()` to verify the actual script content matches expected configuration formats. ## Test Limitations (Acknowledged) The tests verify **template rendering** but not **runtime execution**: | ✅ What we test | ❌ What we don't test | |----------------|----------------------| | Configuration file formats | Script syntax errors at runtime | | Variable interpolation | JFrog CLI compatibility | | Precondition validation | Actual JFrog authentication | | Script contains expected content | Commands execute successfully | **Rationale:** The original TypeScript tests also only checked script content (`toContain()`), not execution. Full execution testing would require a mock JFrog server, which adds significant complexity for limited benefit. The script is straightforward bash that configures files and runs CLI commands. ## Testing ```bash cd registry/coder/modules/jfrog-oauth terraform test # Success! 12 passed, 0 failed. ``` _Generated with [mux](https://github.com/coder/mux)_
1 parent 392f6b1 commit d21db0d

File tree

4 files changed

+409
-191
lines changed

4 files changed

+409
-191
lines changed

registry/coder/modules/jfrog-oauth/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Install the JF CLI and authenticate package managers with Artifactory using OAut
1616
module "jfrog" {
1717
count = data.coder_workspace.me.start_count
1818
source = "registry.coder.com/coder/jfrog-oauth/coder"
19-
version = "1.2.3"
19+
version = "1.2.4"
2020
agent_id = coder_agent.main.id
2121
jfrog_url = "https://example.jfrog.io"
2222
username_field = "username" # If you are using GitHub to login to both Coder and Artifactory, use username_field = "username"
@@ -57,7 +57,7 @@ Configure the Python pip package manager to fetch packages from Artifactory whil
5757
module "jfrog" {
5858
count = data.coder_workspace.me.start_count
5959
source = "registry.coder.com/coder/jfrog-oauth/coder"
60-
version = "1.2.3"
60+
version = "1.2.4"
6161
agent_id = coder_agent.main.id
6262
jfrog_url = "https://example.jfrog.io"
6363
username_field = "email"

0 commit comments

Comments
 (0)