Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
83967a0
Bring work from PR-2245 over
mociarain Aug 7, 2025
c9ace21
Add tests for URL
mociarain Aug 7, 2025
1bd4871
Remove TODOs
mociarain Aug 7, 2025
f1f78c5
Add visibility tests
mociarain Aug 7, 2025
eee8e7a
Add PrefixPolicyType Validation
mociarain Aug 7, 2025
06bae72
Handle it correctly when passing to CS
mociarain Aug 7, 2025
870524f
Fix test
mociarain Aug 8, 2025
d020a72
Add tests for BuildCSExternalAuth
mociarain Aug 8, 2025
bfe2d95
Add test for multiple clients
mociarain Aug 8, 2025
f3dc516
Fix implementation of multiple clients
mociarain Aug 8, 2025
8747f52
Fix []ValidationRules builder logic
mociarain Aug 8, 2025
a4eb70a
Make CA and URL pointers
mociarain Aug 8, 2025
67b62ff
Correctly parse Audiences
mociarain Aug 8, 2025
215e8f4
Flesh out test
mociarain Aug 8, 2025
0ff10f5
Fix syntax
mociarain Aug 8, 2025
628a4ed
Add comment
mociarain Aug 8, 2025
6ef259c
Handle TokenIssuer correctly
mociarain Aug 11, 2025
deb743c
Add a zero test
mociarain Aug 11, 2025
1e2075e
Add test for multiple Taints and fix it
mociarain Aug 11, 2025
586e4fa
Add test for multiple ValidationRules
mociarain Aug 11, 2025
db63eff
Fix typo
mociarain Aug 11, 2025
3b3b9f2
Tidy up
mociarain Aug 11, 2025
2032ccf
Add extra assertion for NodePool create
mociarain Aug 11, 2025
0287804
Move comment back
mociarain Aug 11, 2025
984976e
Tidy imports
mociarain Aug 11, 2025
d56636d
Refactor and fix Claim generation
mociarain Aug 11, 2025
6add773
Fix missing key name
mociarain Aug 11, 2025
094aad8
Fix incorrect json marshaller
mociarain Aug 11, 2025
07632ad
Revert Issuer pointer
mociarain Aug 12, 2025
ea3bdfc
api: External auth token issuer URL will always be present
Aug 13, 2025
c69f83f
api: Add enum value UsernameClaimPrefixPolicyTypeNone
Aug 13, 2025
d91082a
api: Pin autorest/go to 4.0.0-preview.73
Aug 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/autorest-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
input-file: redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/hcpclusters/preview/2024-06-10-preview/openapi.json
use:
- "@autorest/[email protected]"
go:
namespace: redhatopenshift
project-folder: ../internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ model UsernameClaimProfile {
/** Prefix policy is an optional field that configures how a prefix should be
* applied to the value of the JWT claim specified in the 'claim' field.
*
* Allowed values are 'Prefix', 'NoPrefix', and omitted (not provided or an empty string).
* Allowed values are 'Prefix', 'NoPrefix', and 'None'.
*
* When set to 'Prefix', the value specified in the prefix field will be
* prepended to the value of the JWT claim.
Expand All @@ -951,7 +951,7 @@ model UsernameClaimProfile {
* When set to 'NoPrefix', no prefix will be prepended to the value
* of the JWT claim.
*
* When omitted, this means no opinion and the platform is left to choose
* When set to 'None', this means no opinion and the platform is left to choose
* any prefixes that are applied which is subject to change over time.
* Currently, the platform prepends `{issuerURL}#` to the value of the JWT claim
* when the claim is not 'email'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3582,7 +3582,7 @@
},
"prefixPolicy": {
"type": "string",
"description": "Prefix policy is an optional field that configures how a prefix should be\napplied to the value of the JWT claim specified in the 'claim' field.\n\nAllowed values are 'Prefix', 'NoPrefix', and omitted (not provided or an empty string).\n\nWhen set to 'Prefix', the value specified in the prefix field will be\nprepended to the value of the JWT claim.\nThe prefix field must be set when prefixPolicy is 'Prefix'.\n\nWhen set to 'NoPrefix', no prefix will be prepended to the value\nof the JWT claim.\n\nWhen omitted, this means no opinion and the platform is left to choose\nany prefixes that are applied which is subject to change over time.\nCurrently, the platform prepends `{issuerURL}#` to the value of the JWT claim\nwhen the claim is not 'email'.\nAs an example, consider the following scenario:\n`prefix` is unset, `issuerURL` is set to `https://myoidc.tld`,\nthe JWT claims include \"username\":\"userA\" and \"email\":\"userA"
"description": "Prefix policy is an optional field that configures how a prefix should be\napplied to the value of the JWT claim specified in the 'claim' field.\n\nAllowed values are 'Prefix', 'NoPrefix', and 'None'.\n\nWhen set to 'Prefix', the value specified in the prefix field will be\nprepended to the value of the JWT claim.\nThe prefix field must be set when prefixPolicy is 'Prefix'.\n\nWhen set to 'NoPrefix', no prefix will be prepended to the value\nof the JWT claim.\n\nWhen set to 'None', this means no opinion and the platform is left to choose\nany prefixes that are applied which is subject to change over time.\nCurrently, the platform prepends `{issuerURL}#` to the value of the JWT claim\nwhen the claim is not 'email'.\nAs an example, consider the following scenario:\n`prefix` is unset, `issuerURL` is set to `https://myoidc.tld`,\nthe JWT claims include \"username\":\"userA\" and \"email\":\"userA"
}
},
"required": [
Expand All @@ -3605,7 +3605,7 @@
},
"prefixPolicy": {
"type": "string",
"description": "Prefix policy is an optional field that configures how a prefix should be\napplied to the value of the JWT claim specified in the 'claim' field.\n\nAllowed values are 'Prefix', 'NoPrefix', and omitted (not provided or an empty string).\n\nWhen set to 'Prefix', the value specified in the prefix field will be\nprepended to the value of the JWT claim.\nThe prefix field must be set when prefixPolicy is 'Prefix'.\n\nWhen set to 'NoPrefix', no prefix will be prepended to the value\nof the JWT claim.\n\nWhen omitted, this means no opinion and the platform is left to choose\nany prefixes that are applied which is subject to change over time.\nCurrently, the platform prepends `{issuerURL}#` to the value of the JWT claim\nwhen the claim is not 'email'.\nAs an example, consider the following scenario:\n`prefix` is unset, `issuerURL` is set to `https://myoidc.tld`,\nthe JWT claims include \"username\":\"userA\" and \"email\":\"userA"
"description": "Prefix policy is an optional field that configures how a prefix should be\napplied to the value of the JWT claim specified in the 'claim' field.\n\nAllowed values are 'Prefix', 'NoPrefix', and 'None'.\n\nWhen set to 'Prefix', the value specified in the prefix field will be\nprepended to the value of the JWT claim.\nThe prefix field must be set when prefixPolicy is 'Prefix'.\n\nWhen set to 'NoPrefix', no prefix will be prepended to the value\nof the JWT claim.\n\nWhen set to 'None', this means no opinion and the platform is left to choose\nany prefixes that are applied which is subject to change over time.\nCurrently, the platform prepends `{issuerURL}#` to the value of the JWT claim\nwhen the claim is not 'email'.\nAs an example, consider the following scenario:\n`prefix` is unset, `issuerURL` is set to `https://myoidc.tld`,\nthe JWT claims include \"username\":\"userA\" and \"email\":\"userA"
}
}
},
Expand Down
68 changes: 51 additions & 17 deletions frontend/pkg/frontend/external_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"io"
"net/http"
"strings"
"testing"
"time"

Expand All @@ -33,12 +34,11 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

"github.com/Azure/ARO-HCP/internal/api/arm"
// This will invoke the init() function in each
// API version package so it can register itself.
_ "github.com/Azure/ARO-HCP/internal/api/v20240610preview"

"github.com/Azure/ARO-HCP/internal/api"
"github.com/Azure/ARO-HCP/internal/api/arm"
_ "github.com/Azure/ARO-HCP/internal/api/v20240610preview"
"github.com/Azure/ARO-HCP/internal/api/v20240610preview/generated"
"github.com/Azure/ARO-HCP/internal/database"
"github.com/Azure/ARO-HCP/internal/mocks"
Expand All @@ -47,8 +47,23 @@ import (

var dummyExternalAuthHREF = ocm.GenerateExternalAuthHREF(dummyClusterHREF, api.TestExternalAuthName)

var dummyURL = "Spain"
var dummyAudiences = []string{"audience1"}
var dummyURL = "https://redhat.com"
var dummyCA = `-----BEGIN CERTIFICATE-----
MIICMzCCAZygAwIBAgIJALiPnVsvq8dsMA0GCSqGSIb3DQEBBQUAMFMxCzAJBgNV
BAYTAlVTMQwwCgYDVQQIEwNmb28xDDAKBgNVBAcTA2ZvbzEMMAoGA1UEChMDZm9v
MQwwCgYDVQQLEwNmb28xDDAKBgNVBAMTA2ZvbzAeFw0xMzAzMTkxNTQwMTlaFw0x
ODAzMTgxNTQwMTlaMFMxCzAJBgNVBAYTAlVTMQwwCgYDVQQIEwNmb28xDDAKBgNV
BAcTA2ZvbzEMMAoGA1UEChMDZm9vMQwwCgYDVQQLEwNmb28xDDAKBgNVBAMTA2Zv
bzCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAzdGfxi9CNbMf1UUcvDQh7MYB
OveIHyc0E0KIbhjK5FkCBU4CiZrbfHagaW7ZEcN0tt3EvpbOMxxc/ZQU2WN/s/wP
xph0pSfsfFsTKM4RhTWD2v4fgk+xZiKd1p0+L4hTtpwnEw0uXRVd0ki6muwV5y/P
+5FHUeldq+pgTcgzuK8CAwEAAaMPMA0wCwYDVR0PBAQDAgLkMA0GCSqGSIb3DQEB
BQUAA4GBAJiDAAtY0mQQeuxWdzLRzXmjvdSuL9GoyT3BF/jSnpxz5/58dba8pWen
v3pj4P3w5DoOso0rzkZy2jEsEitlVM2mLSbQpMM+MUVQCQoiG6W9xuCFuxSrwPIS
pAqEAuV4DNoxQKKWmhVv+J0ptMWD25Pnpxeq5sXzghfJnslJlQND
-----END CERTIFICATE-----
`
var dummyAudiences = []string{"audience1", "audience2"}
var dummyClaim = "4.18.0"

func TestCreateExternalAuth(t *testing.T) {
Expand All @@ -64,6 +79,7 @@ func TestCreateExternalAuth(t *testing.T) {
Properties: &generated.ExternalAuthProperties{
Issuer: &generated.TokenIssuerProfile{
URL: &dummyURL,
Ca: &dummyCA,
Audiences: api.StringSliceToStringPtrSlice(dummyAudiences),
},
Claim: &generated.ExternalAuthClaimProfile{
Expand All @@ -75,15 +91,32 @@ func TestCreateExternalAuth(t *testing.T) {
},
},
}
expectedCSExternalAuth, _ := arohcpv1alpha1.NewExternalAuth().
ID(strings.ToLower(api.TestExternalAuthName)).
Issuer(arohcpv1alpha1.NewTokenIssuer().
URL(dummyURL).
CA(dummyCA).
Audiences(dummyAudiences...),
).
Claim(arohcpv1alpha1.NewExternalAuthClaim().
Mappings(arohcpv1alpha1.NewTokenClaimMappings().
UserName(arohcpv1alpha1.NewUsernameClaim().
Claim(dummyClaim).
Prefix("").
PrefixPolicy(""),
),
),
).Build()
tests := []struct {
name string
urlPath string
subscription *arm.Subscription
systemData *arm.SystemData
subDoc *arm.Subscription
clusterDoc *database.ResourceDocument
externalAuthDoc *database.ResourceDocument
expectedStatusCode int
name string
urlPath string
subscription *arm.Subscription
systemData *arm.SystemData
subDoc *arm.Subscription
clusterDoc *database.ResourceDocument
externalAuthDoc *database.ResourceDocument
expectedCSExternalAuth *arohcpv1alpha1.ExternalAuth
expectedStatusCode int
}{
{
name: "PUT External Auth - Create a new External Auth",
Expand All @@ -93,9 +126,10 @@ func TestCreateExternalAuth(t *testing.T) {
RegistrationDate: api.Ptr(time.Now().String()),
Properties: nil,
},
clusterDoc: clusterDoc,
externalAuthDoc: externalAuthDoc,
expectedStatusCode: http.StatusCreated,
clusterDoc: clusterDoc,
externalAuthDoc: externalAuthDoc,
expectedCSExternalAuth: expectedCSExternalAuth,
expectedStatusCode: http.StatusCreated,
},
}

Expand Down Expand Up @@ -130,7 +164,7 @@ func TestCreateExternalAuth(t *testing.T) {

// CreateOrUpdateExternalAuth
mockCSClient.EXPECT().
PostExternalAuth(gomock.Any(), clusterDoc.InternalID, gomock.Any()).
PostExternalAuth(gomock.Any(), clusterDoc.InternalID, test.expectedCSExternalAuth).
DoAndReturn(
func(ctx context.Context, clusterInternalID ocm.InternalID, externalAuth *arohcpv1alpha1.ExternalAuth) (*arohcpv1alpha1.ExternalAuth, error) {
builder := arohcpv1alpha1.NewExternalAuth().
Expand Down
28 changes: 27 additions & 1 deletion frontend/pkg/frontend/node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"io"
"net/http"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -73,6 +74,29 @@ func TestCreateNodePool(t *testing.T) {
},
},
}

expectedCSNodePool, _ := arohcpv1alpha1.NewNodePool().
ID(strings.ToLower(api.TestNodePoolName)).
AvailabilityZone("").
AzureNodePool(arohcpv1alpha1.NewAzureNodePool().
ResourceName(strings.ToLower(api.TestNodePoolName)).
VMSize(dummyVMSize).
EncryptionAtHost(
arohcpv1alpha1.NewAzureNodePoolEncryptionAtHost().
State(azureNodePoolEncryptionAtHostDisabled),
).
OSDiskSizeGibibytes(64).
OSDiskStorageAccountType("Premium_LRS"),
).
Labels(make(map[string]string)).
Subnet("").
Version(arohcpv1alpha1.NewVersion().
ID("openshift-v" + dummyVersionID).
ChannelGroup("stable"),
).
Replicas(0).
AutoRepair(true).Build()

tests := []struct {
name string
urlPath string
Expand All @@ -81,6 +105,7 @@ func TestCreateNodePool(t *testing.T) {
subDoc *arm.Subscription
clusterDoc *database.ResourceDocument
nodePoolDoc *database.ResourceDocument
expectedCSNodePool *arohcpv1alpha1.NodePool
expectedStatusCode int
}{
{
Expand All @@ -93,6 +118,7 @@ func TestCreateNodePool(t *testing.T) {
},
clusterDoc: clusterDoc,
nodePoolDoc: nodePoolDoc,
expectedCSNodePool: expectedCSNodePool,
expectedStatusCode: http.StatusCreated,
},
}
Expand Down Expand Up @@ -134,7 +160,7 @@ func TestCreateNodePool(t *testing.T) {
Build())
// CreateOrUpdateNodePool
mockCSClient.EXPECT().
PostNodePool(gomock.Any(), clusterDoc.InternalID, gomock.Any()).
PostNodePool(gomock.Any(), clusterDoc.InternalID, expectedCSNodePool).
DoAndReturn(
func(ctx context.Context, clusterInternalID ocm.InternalID, nodePool *arohcpv1alpha1.NodePool) (*arohcpv1alpha1.NodePool, error) {
builder := arohcpv1alpha1.NewNodePool().
Expand Down
Loading
Loading