Skip to content

Commit 229db7d

Browse files
authored
Feat/ca cleanup enrollment fields (#32)
* feat: add UseForEnrollment and certificate cleanup fields to CA models * fix: restore AccessToken, Audience, Scopes to buildHttpClientV2 OAuth config Commit 2b88eb2 (2026-03-18) accidentally stripped AccessToken, Audience, and Scopes from the CommandConfigOauth struct literal in buildHttpClientV2 in both v1/client.go and v2/client.go. This broke pre-fetched access_token authentication mode where users supply only hostname + access_token without client_id/client_secret/token_url. Restore all three fields so the auth client receives the caller-provided token, audience, and scopes. * test: add OAuth access_token regression tests (unit + integration) * test: add OAuth access_token regression tests for v2 client * test: add regression tests for CA cleanup and enrollment model fields * fix: apply port-443 URL fix and sync CHANGELOG from release-v24.0 * test: port OAuth and CA model regression tests to v25 * chore(docs): add v24.1.1 and v25.1.1 CHANGELOG entries
1 parent af6340b commit 229db7d

11 files changed

Lines changed: 1317 additions & 2 deletions

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
# v25.1.1
2+
3+
## Features
4+
- Add `UseForEnrollment`, `ForceSave`, and certificate cleanup fields (`AllowedEnrollmentTypes`, `StandaloneCA`, `MonitorThresholds`, `FullScanIntervalMinutes`, `IncrementalScanIntervalMinutes`) to CA request/response models in `v25/api/keyfactor/v1`
5+
6+
## Fixes
7+
- Restore `AccessToken`, `Audience`, `Scopes` fields to `buildHttpClientV2` OAuth config (fields were silently dropped in prior refactor)
8+
- Skip appending port 443 to request URL to avoid duplicate port in HTTPS connections
9+
10+
## Tests
11+
- Add OAuth `access_token`/`audience`/`scopes` field propagation regression tests for v1 and v2 clients
12+
- Add CA model regression tests covering cleanup and enrollment fields
13+
14+
# v24.1.1
15+
16+
## Features
17+
- Add `UseForEnrollment`, `ForceSave`, and certificate cleanup fields (`AllowedEnrollmentTypes`, `StandaloneCA`, `MonitorThresholds`, `FullScanIntervalMinutes`, `IncrementalScanIntervalMinutes`) to CA request/response models in `v24/api/keyfactor/v1`
18+
19+
## Fixes
20+
- Restore `AccessToken`, `Audience`, `Scopes` fields to `buildHttpClientV2` OAuth config (fields were silently dropped in prior refactor)
21+
- Skip appending port 443 to request URL to avoid duplicate port in HTTPS connections
22+
23+
## Tests
24+
- Add OAuth `access_token`/`audience`/`scopes` field propagation regression tests for v1 and v2 clients
25+
- Add CA model regression tests covering cleanup and enrollment fields
26+
127
# v25.0.1
228

329
## Chores
@@ -12,6 +38,14 @@
1238
- Support for Keyfactor Command REST API endpoints up to 25.1.1. [API Change Log](https://software.keyfactor.com/Core-OnPrem/Current/Content/WebAPI/ChangeLogs/25_1_1-APIChangeLog.htm)
1339
- Add [helper methods](https://github.com/Keyfactor/keyfactor-go-client-sdk/blob/feat/AB%2372090/sdk-version-25/v25/helpers.go) to support some common lookup patterns.
1440

41+
# v24.0.1
42+
## Chores
43+
- Bump github.com/Keyfactor/keyfactor-auth-client-go dependency from v1.1.0-rc.8 to 1.3.0.
44+
45+
## Fixes
46+
- fix: Fix issue with the OAuth token flow with explicit access token provided to config runs into an error
47+
- fix: Skip appending port 443 to request URL to avoid duplicate port in HTTPS connections
48+
1549
# v24.0.0
1650

1751
## Features

v24/api/keyfactor/v1/client.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package v1
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
7+
"github.com/Keyfactor/keyfactor-auth-client-go/auth_providers"
8+
)
9+
10+
// TestCommandConfigOauth_AccessTokenFieldPropagation is a compilation + correctness
11+
// regression test for the v2.8.0 bug where AccessToken, Audience, and Scopes were
12+
// silently dropped when constructing CommandConfigOauth from auth_providers.Server
13+
// in buildHttpClientV2. If any of those three fields are ever removed from either
14+
// struct, this test fails to compile.
15+
func TestCommandConfigOauth_AccessTokenFieldPropagation(t *testing.T) {
16+
srv := &auth_providers.Server{
17+
Host: "test.example.com",
18+
AccessToken: "mytoken-abc123",
19+
Audience: "https://my.audience.example.com",
20+
Scopes: []string{"read", "write", "admin"},
21+
}
22+
23+
// Step 1: Verify Server struct holds the fields correctly
24+
if srv.AccessToken != "mytoken-abc123" {
25+
t.Errorf("Server.AccessToken = %q, want %q", srv.AccessToken, "mytoken-abc123")
26+
}
27+
if srv.Audience != "https://my.audience.example.com" {
28+
t.Errorf("Server.Audience = %q, want %q", srv.Audience, "https://my.audience.example.com")
29+
}
30+
if !reflect.DeepEqual(srv.Scopes, []string{"read", "write", "admin"}) {
31+
t.Errorf("Server.Scopes = %v, want %v", srv.Scopes, []string{"read", "write", "admin"})
32+
}
33+
34+
// Step 2: Construct CommandConfigOauth the same way buildHttpClientV2 does
35+
// (minus the Authenticate() call which requires network). This mirrors lines
36+
// 344-351 of client.go exactly.
37+
baseConfig := auth_providers.CommandAuthConfig{
38+
CommandHostName: srv.Host,
39+
CommandPort: srv.Port,
40+
CommandAPIPath: srv.APIPath,
41+
CommandCACert: srv.CACertPath,
42+
SkipVerify: srv.SkipTLSVerify,
43+
}
44+
oauthCfg := auth_providers.CommandConfigOauth{
45+
CommandAuthConfig: baseConfig,
46+
ClientID: srv.ClientID,
47+
ClientSecret: srv.ClientSecret,
48+
TokenURL: srv.OAuthTokenUrl,
49+
AccessToken: srv.AccessToken,
50+
Audience: srv.Audience,
51+
Scopes: srv.Scopes,
52+
}
53+
54+
// Step 3: Verify the three fields that were missing in the v2.8.0 regression
55+
if oauthCfg.AccessToken != "mytoken-abc123" {
56+
t.Errorf("CommandConfigOauth.AccessToken = %q, want %q", oauthCfg.AccessToken, "mytoken-abc123")
57+
}
58+
if oauthCfg.Audience != "https://my.audience.example.com" {
59+
t.Errorf("CommandConfigOauth.Audience = %q, want %q", oauthCfg.Audience, "https://my.audience.example.com")
60+
}
61+
if !reflect.DeepEqual(oauthCfg.Scopes, []string{"read", "write", "admin"}) {
62+
t.Errorf("CommandConfigOauth.Scopes = %v, want %v", oauthCfg.Scopes, []string{"read", "write", "admin"})
63+
}
64+
65+
// Step 4: Verify GetAuthType returns "oauth" for access_token-only config
66+
authType := srv.GetAuthType()
67+
if authType != "oauth" {
68+
t.Errorf("Server.GetAuthType() = %q, want %q (access_token-only should be oauth)", authType, "oauth")
69+
}
70+
}
71+
72+
// TestCommandConfigOauth_AccessTokenOnlyNoClientCreds verifies that a Server
73+
// configured with only Host + AccessToken (no ClientID/ClientSecret/TokenURL)
74+
// is classified as "oauth" auth type and the token propagates correctly.
75+
func TestCommandConfigOauth_AccessTokenOnlyNoClientCreds(t *testing.T) {
76+
srv := &auth_providers.Server{
77+
Host: "command.example.com",
78+
AccessToken: "pre-fetched-bearer-token",
79+
// Deliberately omitting ClientID, ClientSecret, OAuthTokenUrl
80+
}
81+
82+
if got := srv.GetAuthType(); got != "oauth" {
83+
t.Fatalf("GetAuthType() = %q, want %q for access_token-only", got, "oauth")
84+
}
85+
86+
oauthCfg := auth_providers.CommandConfigOauth{
87+
AccessToken: srv.AccessToken,
88+
}
89+
90+
if oauthCfg.AccessToken != "pre-fetched-bearer-token" {
91+
t.Errorf("AccessToken = %q, want %q", oauthCfg.AccessToken, "pre-fetched-bearer-token")
92+
}
93+
if oauthCfg.ClientID != "" {
94+
t.Errorf("ClientID = %q, want empty", oauthCfg.ClientID)
95+
}
96+
if oauthCfg.ClientSecret != "" {
97+
t.Errorf("ClientSecret = %q, want empty", oauthCfg.ClientSecret)
98+
}
99+
}

v24/api/keyfactor/v1/model_certificate_authorities_certificate_authority_request.go

Lines changed: 138 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)