Skip to content

Commit efc0f90

Browse files
committed
validaties
1 parent 71ddbd0 commit efc0f90

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

api/v3/wfs_validation.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ func ValidateWFS(wfs *WFS, warnings *[]string, allErrs *field.ErrorList) {
5050
)
5151
}
5252

53+
crsses := []string{}
54+
for i, crs := range service.OtherCrs {
55+
if slices.Contains(crsses, crs) {
56+
*allErrs = append(*allErrs, field.Duplicate(
57+
path.Child("otherCrs").Index(i),
58+
crs,
59+
))
60+
} else {
61+
crsses = append(crsses, crs)
62+
}
63+
}
64+
5365
ValidateInspire(wfs, allErrs)
5466

5567
if wfs.Spec.HorizontalPodAutoscalerPatch != nil {

api/v3/wms_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ type Layer struct {
249249
}
250250

251251
type WMSBoundingBox struct {
252+
// +kubebuilder:validation:Pattern:="^(EPSG:(28992|25831|25832|3034|3035|3857|4258|4326)|CRS:84)$"
252253
CRS string `json:"crs"`
253254
BBox smoothoperatormodel.BBox `json:"bbox"`
254255
}

api/v3/wms_validation.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ func validateLayer(layer AnnotatedLayer, path *field.Path, groupStyles []string,
122122
validateNotVisibleLayer(layer, path, wms, warnings, allErrs)
123123
}
124124

125+
crsses := []string{}
126+
for i, bbox := range layer.BoundingBoxes {
127+
if slices.Contains(crsses, bbox.CRS) {
128+
*allErrs = append(*allErrs, field.Duplicate(
129+
path.Child("boundingBoxes").Index(i).Child("crs"),
130+
bbox.CRS,
131+
))
132+
} else {
133+
crsses = append(crsses, bbox.CRS)
134+
}
135+
}
136+
125137
styleNames := []string{}
126138
for i, style := range layer.Styles {
127139
stylePath := path.Child("styles").Index(i)

config/crd/bases/pdok.nl_wms.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,7 @@ spec:
13231323
- miny
13241324
type: object
13251325
crs:
1326+
pattern: ^(EPSG:(28992|25831|25832|3034|3035|3857|4258|4326)|CRS:84)$
13261327
type: string
13271328
required:
13281329
- bbox
@@ -1421,6 +1422,7 @@ spec:
14211422
- miny
14221423
type: object
14231424
crs:
1425+
pattern: ^(EPSG:(28992|25831|25832|3034|3035|3857|4258|4326)|CRS:84)$
14241426
type: string
14251427
required:
14261428
- bbox
@@ -1625,6 +1627,7 @@ spec:
16251627
- miny
16261628
type: object
16271629
crs:
1630+
pattern: ^(EPSG:(28992|25831|25832|3034|3035|3857|4258|4326)|CRS:84)$
16281631
type: string
16291632
required:
16301633
- bbox

internal/webhook/v3/wfs_webhook_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ var _ = Describe("WFS Webhook", func() {
152152
))))
153153
})
154154

155+
It("Should deny Create when a otherCrs has the same crs multiple times", func() {
156+
crs := "EPSG:3035"
157+
obj.Spec.Service.OtherCrs = []string{crs, crs}
158+
159+
warnings, err := validator.ValidateCreate(ctx, obj)
160+
Expect(err).To(Equal(getValidationError(obj, field.Duplicate(
161+
field.NewPath("spec").Child("service").Child("otherCrs").Index(1),
162+
crs,
163+
))))
164+
Expect(warnings).To(BeEmpty())
165+
})
166+
155167
It("Should deny creation if SpatialID is also used as a featureType datasetMetadataID", func() {
156168
Expect(obj.Inspire()).NotTo(BeNil())
157169
Expect(obj.Spec.Service.FeatureTypes[0].DatasetMetadataURL).NotTo(BeNil())

internal/webhook/v3/wms_webhook_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,26 @@ var _ = Describe("WMS Webhook", func() {
330330
)))))))))
331331
})
332332

333+
It("Should deny Create when a Layer has multiple boundingBoxes with the same CRS", func() {
334+
bbox := pdoknlv3.WMSBoundingBox{
335+
CRS: "EPSG:28992",
336+
BBox: smoothoperatormodel.BBox{
337+
MinX: "-25000",
338+
MinY: "250000",
339+
MaxX: "280000",
340+
MaxY: "860000",
341+
},
342+
}
343+
obj.Spec.Service.Layer.BoundingBoxes = []pdoknlv3.WMSBoundingBox{bbox, bbox}
344+
345+
warnings, err := validator.ValidateCreate(ctx, obj)
346+
Expect(err).To(Equal(getValidationError(obj, field.Duplicate(
347+
field.NewPath("spec").Child("service").Child("layer").Child("boundingBoxes").Index(1).Child("crs"),
348+
bbox.CRS,
349+
))))
350+
Expect(warnings).To(BeEmpty())
351+
})
352+
333353
It("Should deny Create when a Layer uses the same style name multiple times", func() {
334354
styleName := "duplicate"
335355
style := pdoknlv3.Style{

0 commit comments

Comments
 (0)