Skip to content

Commit 820b04b

Browse files
committed
Updates per Ethan review
1 parent aa2f45c commit 820b04b

File tree

5 files changed

+14
-151
lines changed

5 files changed

+14
-151
lines changed

api/pkg/template/license.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,6 @@ import (
1010
"github.com/replicatedhq/embedded-cluster/pkg/release"
1111
)
1212

13-
// Helper methods for direct access (used by tests and other code)
14-
func (e *Engine) LicenseAppSlug() string {
15-
if e.license.IsEmpty() {
16-
return ""
17-
}
18-
return e.license.GetAppSlug()
19-
}
20-
21-
func (e *Engine) LicenseID() string {
22-
if e.license.IsEmpty() {
23-
return ""
24-
}
25-
return e.license.GetLicenseID()
26-
}
27-
28-
func (e *Engine) LicenseIsEmbeddedClusterDownloadEnabled() bool {
29-
if e.license.IsEmpty() {
30-
return false
31-
}
32-
return e.license.IsEmbeddedClusterDownloadEnabled()
33-
}
34-
3513
func (e *Engine) licenseFieldValue(name string) (string, error) {
3614
if e.license.IsEmpty() {
3715
return "", fmt.Errorf("license is nil")

api/pkg/template/license_test.go

Lines changed: 13 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,32 @@ import (
44
"encoding/base64"
55
"encoding/json"
66
"fmt"
7+
"os"
78
"testing"
89

910
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
1011
"github.com/replicatedhq/embedded-cluster/pkg/release"
1112
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
13+
kotsv1beta2 "github.com/replicatedhq/kotskinds/apis/kots/v1beta2"
1214
"github.com/replicatedhq/kotskinds/pkg/licensewrapper"
1315
"github.com/stretchr/testify/assert"
1416
"github.com/stretchr/testify/require"
1517
)
1618

17-
// Helper function to wrap old-style license in LicenseWrapper for testing
19+
// Helper function to wrap v1beta1 license in LicenseWrapper for testing
1820
func wrapLicense(license *kotsv1beta1.License) *licensewrapper.LicenseWrapper {
1921
return &licensewrapper.LicenseWrapper{
2022
V1: license,
2123
}
2224
}
2325

26+
// Helper function to wrap v1beta2 license in LicenseWrapper for testing
27+
func wrapLicenseV2(license *kotsv1beta2.License) *licensewrapper.LicenseWrapper {
28+
return &licensewrapper.LicenseWrapper{
29+
V2: license,
30+
}
31+
}
32+
2433
func TestEngine_LicenseFieldValue(t *testing.T) {
2534
license := &kotsv1beta1.License{
2635
Spec: kotsv1beta1.LicenseSpec{
@@ -175,8 +184,8 @@ func TestEngine_LicenseFieldValue_Endpoint(t *testing.T) {
175184
}
176185

177186
func TestEngine_LicenseFieldValue_EndpointWithoutReleaseData(t *testing.T) {
178-
license := &kotsv1beta1.License{
179-
Spec: kotsv1beta1.LicenseSpec{
187+
license := &kotsv1beta2.License{
188+
Spec: kotsv1beta2.LicenseSpec{
180189
CustomerName: "Acme Corp",
181190
LicenseID: "license-123",
182191
},
@@ -188,7 +197,7 @@ func TestEngine_LicenseFieldValue_EndpointWithoutReleaseData(t *testing.T) {
188197
},
189198
}
190199

191-
engine := NewEngine(config, WithLicense(wrapLicense(license)))
200+
engine := NewEngine(config, WithLicense(wrapLicenseV2(license)))
192201

193202
err := engine.Parse("{{repl LicenseFieldValue \"endpoint\" }}")
194203
require.NoError(t, err)
@@ -606,113 +615,3 @@ func TestEngine_ChannelName_ChannelNotFound(t *testing.T) {
606615
assert.Error(t, err)
607616
assert.Contains(t, err.Error(), "channel unknown-channel-id not found in license")
608617
}
609-
610-
func TestEngine_LicenseWrapper(t *testing.T) {
611-
licenseV1Beta1 := `apiVersion: kots.io/v1beta1
612-
kind: License
613-
metadata:
614-
name: test-license
615-
spec:
616-
appSlug: embedded-cluster-test
617-
licenseID: test-license-id-v1
618-
licenseType: dev
619-
customerName: Test Customer V1
620-
customerEmail: [email protected]
621-
endpoint: https://replicated.app
622-
channelID: test-channel-id
623-
channelName: Stable
624-
licenseSequence: 1
625-
isAirgapSupported: true
626-
isGitOpsSupported: false
627-
isIdentityServiceSupported: false
628-
isGeoaxisSupported: false
629-
isSnapshotSupported: true
630-
isSupportBundleUploadSupported: true
631-
isSemverRequired: true
632-
isDisasterRecoverySupported: true
633-
isEmbeddedClusterDownloadEnabled: true
634-
isEmbeddedClusterMultiNodeEnabled: true
635-
replicatedProxyDomain: proxy.replicated.com
636-
entitlements:
637-
expires_at:
638-
title: Expiration
639-
description: License Expiration
640-
value: ""
641-
valueType: String
642-
signature: {}
643-
channels: []
644-
signature: dGVzdC1saWNlbnNlLXNpZ25hdHVyZQ==
645-
`
646-
647-
licenseV1Beta2 := `apiVersion: kots.io/v1beta2
648-
kind: License
649-
metadata:
650-
name: test-license
651-
spec:
652-
appSlug: embedded-cluster-test
653-
licenseID: test-license-id-v2
654-
licenseType: dev
655-
customerName: Test Customer V2
656-
customerEmail: [email protected]
657-
endpoint: https://replicated.app
658-
channelID: test-channel-id
659-
channelName: Stable
660-
licenseSequence: 1
661-
isAirgapSupported: true
662-
isGitOpsSupported: false
663-
isIdentityServiceSupported: false
664-
isGeoaxisSupported: false
665-
isSnapshotSupported: true
666-
isSupportBundleUploadSupported: true
667-
isSemverRequired: true
668-
isDisasterRecoverySupported: true
669-
isEmbeddedClusterDownloadEnabled: true
670-
isEmbeddedClusterMultiNodeEnabled: true
671-
replicatedProxyDomain: proxy.replicated.com
672-
entitlements:
673-
expires_at:
674-
title: Expiration
675-
description: License Expiration
676-
value: ""
677-
valueType: String
678-
signature: {}
679-
channels: []
680-
signature: dGVzdC1saWNlbnNlLXNpZ25hdHVyZQ==
681-
`
682-
683-
tests := []struct {
684-
name string
685-
licenseData string
686-
wantAppSlug string
687-
wantLicenseID string
688-
wantECEnabled bool
689-
}{
690-
{
691-
name: "v1beta1 license",
692-
licenseData: licenseV1Beta1,
693-
wantAppSlug: "embedded-cluster-test",
694-
wantLicenseID: "test-license-id-v1",
695-
wantECEnabled: true,
696-
},
697-
{
698-
name: "v1beta2 license",
699-
licenseData: licenseV1Beta2,
700-
wantAppSlug: "embedded-cluster-test",
701-
wantLicenseID: "test-license-id-v2",
702-
wantECEnabled: true,
703-
},
704-
}
705-
706-
for _, tt := range tests {
707-
t.Run(tt.name, func(t *testing.T) {
708-
wrapper, err := licensewrapper.LoadLicenseFromBytes([]byte(tt.licenseData))
709-
require.NoError(t, err)
710-
711-
engine := NewEngine(nil, WithLicense(&wrapper))
712-
713-
assert.Equal(t, tt.wantAppSlug, engine.LicenseAppSlug())
714-
assert.Equal(t, tt.wantLicenseID, engine.LicenseID())
715-
assert.Equal(t, tt.wantECEnabled, engine.LicenseIsEmbeddedClusterDownloadEnabled())
716-
})
717-
}
718-
}

pkg-new/license/signature.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ swIDAQAB
7878
// It handles both v1beta1 and v1beta2 licenses by delegating to their ValidateLicense methods.
7979
// Returns the wrapper unchanged if validation succeeds, or an error if validation fails.
8080
func VerifySignature(wrapper *licensewrapper.LicenseWrapper) (*licensewrapper.LicenseWrapper, error) {
81-
if wrapper == nil || wrapper.IsEmpty() {
82-
// Empty wrapper doesn't need verification
83-
return wrapper, nil
84-
}
85-
8681
if wrapper.IsV1() {
8782
_, err := wrapper.V1.ValidateLicense()
8883
if err != nil {

pkg-new/license/signature_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@ func Test_VerifySignature(t *testing.T) {
5757
expectError: true,
5858
errorContains: "verification error",
5959
},
60-
{
61-
name: "nil wrapper returns nil",
62-
wrapper: nil,
63-
expectError: false,
64-
},
65-
{
66-
name: "empty wrapper returns wrapper",
67-
wrapper: &licensewrapper.LicenseWrapper{},
68-
expectError: false,
69-
},
7060
{
7161
name: "v1beta2: valid signature passes verification",
7262
licenseFile: "testdata/valid-license-v2.yaml",

pkg-new/replicatedapi/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func (c *client) newRetryableRequest(ctx context.Context, method string, url str
151151
// injectHeaders injects the basic auth header, user agent header, and reporting info headers into the http.Header.
152152
func (c *client) injectHeaders(header http.Header) {
153153
licenseID := c.license.GetLicenseID()
154+
header.Set("Authorization", "Basic "+basicAuth(licenseID, licenseID))
154155
header.Set("User-Agent", fmt.Sprintf("Embedded-Cluster/%s", versions.Version))
155156

156157
// Add license version header for v1beta2 licenses

0 commit comments

Comments
 (0)