Skip to content

Commit 6052958

Browse files
authored
GT-452 Improve master endpoint validation (#1339)
1 parent c0afad6 commit 6052958

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Improvement) Block traffic on the services if there is more than 1 active leader in ActiveFailover mode
5+
- (Improvement) Improve master endpoint validation.
56

67
## [1.2.30](https://github.com/arangodb/kube-arangodb/tree/1.2.30) (2023-06-16)
78
- (Feature) AgencyCache Interface

pkg/apis/deployment/v1/sync_external_access_spec.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,15 @@ func (s SyncExternalAccessSpec) Validate() error {
6363
return errors.WithStack(err)
6464
}
6565
for _, ep := range s.MasterEndpoint {
66-
if _, err := url.Parse(ep); err != nil {
66+
if u, err := url.Parse(ep); err != nil {
6767
return errors.WithStack(errors.Newf("Failed to parse master endpoint '%s': %s", ep, err))
68+
} else {
69+
if u.Scheme != "http" && u.Scheme != "https" {
70+
return errors.WithStack(errors.Newf("Invalid scheme '%s' in master endpoint '%s'", u.Scheme, ep))
71+
}
72+
if u.Host == "" {
73+
return errors.WithStack(errors.Newf("Missing host in master endpoint '%s'", ep))
74+
}
6875
}
6976
}
7077
for _, name := range s.AccessPackageSecretNames {

pkg/apis/deployment/v1/sync_spec_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,37 @@ func TestSyncSpecResetImmutableFields(t *testing.T) {
102102
assert.Equal(t, test.Expected, test.Target)
103103
}
104104
}
105+
106+
func TestSyncSpecMasterEndpointValidate(t *testing.T) {
107+
auth := SyncAuthenticationSpec{
108+
JWTSecretName: util.NewType[string]("foo"),
109+
ClientCASecretName: util.NewType[string]("foo-client"),
110+
}
111+
tls := TLSSpec{
112+
CASecretName: util.NewType[string]("None"),
113+
}
114+
t.Run("Valid MasterEndpoint", func(t *testing.T) {
115+
err := SyncSpec{
116+
Authentication: auth,
117+
TLS: tls,
118+
ExternalAccess: SyncExternalAccessSpec{
119+
MasterEndpoint: []string{"https://arangodb.xyz:8629"},
120+
},
121+
Enabled: util.NewType[bool](true),
122+
}.Validate(DeploymentModeCluster)
123+
assert.Nil(t, err)
124+
})
125+
126+
t.Run("Invalid MasterEndpoint without protocol", func(t *testing.T) {
127+
err := SyncSpec{
128+
Authentication: auth,
129+
TLS: tls,
130+
ExternalAccess: SyncExternalAccessSpec{
131+
MasterEndpoint: []string{"example.com:8629"},
132+
},
133+
Enabled: util.NewType[bool](true),
134+
}.Validate(DeploymentModeCluster)
135+
assert.Error(t, err)
136+
assert.Equal(t, "Invalid scheme 'example.com' in master endpoint 'example.com:8629'", err.Error())
137+
})
138+
}

0 commit comments

Comments
 (0)