Skip to content

Commit

Permalink
Redirect assertion
Browse files Browse the repository at this point in the history
Signed-off-by: Fernando Cainelli <[email protected]>
  • Loading branch information
cainelli committed Sep 23, 2024
1 parent 84a9ed6 commit 8c65b91
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ jobs:
run: go test -vet=off -count=1 ./...
- name: Test with -race
run: go test -vet=off -race -count=1 ./...
- name: Run
run: make run
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ WORKDIR = /src/github.com/getyourguide.com/istio-config-validator


run:
docker run -it --rm --name istio_config_validator \
-v ${CURRENTPATH}:${WORKDIR} \
-w ${WORKDIR} \
golang:1.22 \
go run cmd/istio-config-validator/main.go -t examples/ examples/
go run cmd/istio-config-validator/main.go -t examples/ examples/

build:
go build -o istio-config-validator cmd/istio-config-validator/main.go
Expand Down
8 changes: 4 additions & 4 deletions examples/multidocument_virtualservice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ spec:
gateways:
- mesh
hosts:
- www.example.com
- example.com
- www.example2.com
- example2.com
http:
- match:
- uri:
Expand All @@ -32,8 +32,8 @@ spec:
gateways:
- mesh
hosts:
- www.example.com
- example.com
- www.example3.com
- example3.com
http:
- match:
- uri:
Expand Down
8 changes: 7 additions & 1 deletion examples/virtualservice.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: networking.istio.io/v1alpha3
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: example
Expand All @@ -10,6 +10,12 @@ spec:
- www.example.com
- example.com
http:
- match:
- uri:
prefix: /home
redirect:
uri: /
authority: www.example.com
- match:
- uri:
regex: /users(/.*)?
Expand Down
9 changes: 9 additions & 0 deletions examples/virtualservice_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ testCases:
---
# Multidoc test
testCases:
- description: Redirect /home to /
wantMatch: true
request:
authority: ["www.example.com"]
method: ["GET"]
uri: ["/home"]
redirect:
uri: "/"
authority: "www.example.com"
- description: Reseller is rewritten as partner
wantMatch: true
request:
Expand Down
9 changes: 4 additions & 5 deletions internal/pkg/istio-router-check/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func (c *RootCommand) prepareTests(ctx context.Context) error {
log.V(LevelDebug).Info("skipping rewrite test", "test", tc.Description, "reason", "format assertion is different in envoy tests")
continue
}
if tc.Redirect != nil {
log.V(LevelDebug).Info("skipping redirect test", "test", tc.Description, "reason", "format assertion is different in envoy tests")
continue
}
for _, req := range inputs {
var reqHeaders []envoy.Header
for key, value := range req.Headers {
Expand Down Expand Up @@ -243,10 +247,5 @@ func convertValidate(input envoy.Input, tc *parser.TestCase) (envoy.Validate, er
route.GetDestination().GetHost(),
)
}
if tc.Redirect != nil {
authority := cmp.Or(tc.Redirect.GetAuthority(), input.Authority)
scheme := cmp.Or(tc.Redirect.GetScheme(), "https")
output.PathRedirect = fmt.Sprintf("%s://%s%s", scheme, authority, tc.Redirect.GetUri())
}
return output, nil
}
7 changes: 6 additions & 1 deletion internal/pkg/unit/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ func Run(testfiles, configfiles []string, strict bool) ([]string, []string, erro
return summary, details, fmt.Errorf("headers missmatch=%v, want %v, rule matched: %v", route.Headers, testCase.Headers, route.Match)
}
}

if testCase.Redirect != nil {
if reflect.DeepEqual(route.Redirect, testCase.Redirect) != testCase.WantMatch {
details = append(details, fmt.Sprintf("FAIL input:[%v]", input))
return summary, details, fmt.Errorf("redirect missmatch=%v, want %v, rule matched: %v", route.Redirect, testCase.Redirect, route.Match)
}
}
details = append(details, fmt.Sprintf("PASS input:[%v]", input))
}
inputCount += len(inputs)
Expand Down

0 comments on commit 8c65b91

Please sign in to comment.