Add Certificates page and Traefik API frontend client
This commit is contained in:
parent
9e4c612dcb
commit
7fc90524b5
40 changed files with 6585 additions and 359 deletions
198
backend/internal/config/file/validate_traefik_test.go
Normal file
198
backend/internal/config/file/validate_traefik_test.go
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
package file
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestValidateContent_InvalidRouterRule(t *testing.T) {
|
||||
// missing rule
|
||||
yaml := `http:
|
||||
routers:
|
||||
bad-router:
|
||||
service: svc1
|
||||
services:
|
||||
svc1:
|
||||
loadBalancer:
|
||||
servers:
|
||||
- url: "http://127.0.0.1:8080"
|
||||
`
|
||||
errs := ValidateContent("app.yml", yaml)
|
||||
if len(errs) == 0 {
|
||||
t.Fatalf("expected error for missing rule")
|
||||
}
|
||||
found := false
|
||||
for _, e := range errs {
|
||||
if containsStr(e.Message, "rule") {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("expected rule error, got %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateContent_InvalidService(t *testing.T) {
|
||||
yaml := `http:
|
||||
routers:
|
||||
r1:
|
||||
rule: "Host(` + "`a.com`" + `)"
|
||||
service: svc1
|
||||
services:
|
||||
svc1: {}
|
||||
`
|
||||
errs := ValidateContent("app.yml", yaml)
|
||||
found := false
|
||||
for _, e := range errs {
|
||||
if containsStr(e.Message, "loadBalancer") {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("expected service definition error, got %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateContent_InvalidMiddleware(t *testing.T) {
|
||||
yaml := `http:
|
||||
routers:
|
||||
r1:
|
||||
rule: "Host(` + "`a.com`" + `)"
|
||||
service: s1
|
||||
services:
|
||||
s1:
|
||||
loadBalancer:
|
||||
servers:
|
||||
- url: "http://127.0.0.1:8080"
|
||||
middlewares:
|
||||
m1: "not-a-mapping"
|
||||
`
|
||||
errs := ValidateContent("app.yml", yaml)
|
||||
found := false
|
||||
for _, e := range errs {
|
||||
if containsStr(e.Message, "middlewares") {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("expected middleware error, got %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateContent_TCPInvalid(t *testing.T) {
|
||||
yaml := `tcp:
|
||||
routers:
|
||||
tr1:
|
||||
service: svc1
|
||||
`
|
||||
errs := ValidateContent("app.yml", yaml)
|
||||
found := false
|
||||
for _, e := range errs {
|
||||
if containsStr(e.Message, "tcp.routers") && containsStr(e.Message, "rule") {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("expected tcp router rule error, got %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateContent_UDPUnknownField(t *testing.T) {
|
||||
yaml := `udp:
|
||||
routers:
|
||||
r1:
|
||||
entryPoints: ["udp"]
|
||||
service: svc1
|
||||
services:
|
||||
svc1:
|
||||
loadBalancer:
|
||||
servers:
|
||||
- address: "127.0.0.1:5000"
|
||||
unknown: foo
|
||||
`
|
||||
errs := ValidateContent("app.yml", yaml)
|
||||
found := false
|
||||
for _, e := range errs {
|
||||
if containsStr(e.Message, "udp: unknown key") {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("expected udp unknown field error, got %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateContent_TLSInvalid(t *testing.T) {
|
||||
yaml := `tls:
|
||||
certificates:
|
||||
- certFile: "/certs/cert.pem"
|
||||
invalidKey: foo
|
||||
`
|
||||
errs := ValidateContent("app.yml", yaml)
|
||||
found := false
|
||||
for _, e := range errs {
|
||||
if containsStr(e.Message, "tls: unknown") {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("expected tls unknown key error, got %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateContent_UnknownNestedHTTP(t *testing.T) {
|
||||
yaml := `http:
|
||||
routers:
|
||||
r1:
|
||||
rule: "Host(` + "`a.com`" + `)"
|
||||
service: s1
|
||||
services:
|
||||
s1:
|
||||
loadBalancer:
|
||||
servers:
|
||||
- url: "http://127.0.0.1:8080"
|
||||
unknownSection: foo
|
||||
`
|
||||
errs := ValidateContent("app.yml", yaml)
|
||||
found := false
|
||||
for _, e := range errs {
|
||||
if containsStr(e.Message, "http: unknown key") {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("expected http unknown nested error, got %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateContent_ServiceMissingURL(t *testing.T) {
|
||||
yaml := `http:
|
||||
routers:
|
||||
r1:
|
||||
rule: "Host(` + "`a.com`" + `)"
|
||||
service: s1
|
||||
services:
|
||||
s1:
|
||||
loadBalancer:
|
||||
servers:
|
||||
- weight: 1
|
||||
`
|
||||
errs := ValidateContent("app.yml", yaml)
|
||||
found := false
|
||||
for _, e := range errs {
|
||||
if containsStr(e.Message, "missing 'url'") {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("expected missing url error, got %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
func containsStr(s, sub string) bool {
|
||||
return len(s) >= len(sub) && (func() bool {
|
||||
for i := 0; i <= len(s)-len(sub); i++ {
|
||||
if s[i:i+len(sub)] == sub {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
})()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue