Browse Source

httpcaddyfile: Decrement counter when removing conn policy (fix #3906)

master
Matthew Holt 5 years ago
parent
commit
7e719157d9
No known key found for this signature in database GPG Key ID: 2A349DD577D586A5
  1. 2
      caddyconfig/httpcaddyfile/tlsapp.go
  2. 137
      caddytest/integration/caddyfile_adapt/tls_conn_policy_consolidate.txt

2
caddyconfig/httpcaddyfile/tlsapp.go

@ -487,6 +487,7 @@ func consolidateAutomationPolicies(aps []*caddytls.AutomationPolicy) []*caddytls
// remove or combine duplicate policies // remove or combine duplicate policies
for i := 0; i < len(aps); i++ { for i := 0; i < len(aps); i++ {
// compare only with next policies; we sorted by specificity so we must not delete earlier policies
for j := i + 1; j < len(aps); j++ { for j := i + 1; j < len(aps); j++ {
// if they're exactly equal in every way, just keep one of them // if they're exactly equal in every way, just keep one of them
if reflect.DeepEqual(aps[i], aps[j]) { if reflect.DeepEqual(aps[i], aps[j]) {
@ -526,6 +527,7 @@ func consolidateAutomationPolicies(aps []*caddytls.AutomationPolicy) []*caddytls
} }
} }
aps = append(aps[:j], aps[j+1:]...) aps = append(aps[:j], aps[j+1:]...)
j--
} }
} }
} }

137
caddytest/integration/caddyfile_adapt/tls_conn_policy_consolidate.txt

@ -0,0 +1,137 @@
# https://github.com/caddyserver/caddy/issues/3906
a.a {
tls internal
respond 403
}
http://b.b https://b.b:8443 {
tls internal
respond 404
}
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"match": [
{
"host": [
"a.a"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "static_response",
"status_code": 403
}
]
}
]
}
],
"terminal": true
}
]
},
"srv1": {
"listen": [
":80"
],
"routes": [
{
"match": [
{
"host": [
"b.b"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "static_response",
"status_code": 404
}
]
}
]
}
],
"terminal": true
}
],
"automatic_https": {
"skip": [
"b.b"
]
}
},
"srv2": {
"listen": [
":8443"
],
"routes": [
{
"match": [
{
"host": [
"b.b"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "static_response",
"status_code": 404
}
]
}
]
}
],
"terminal": true
}
]
}
}
},
"tls": {
"automation": {
"policies": [
{
"subjects": [
"a.a",
"b.b"
],
"issuers": [
{
"module": "internal"
}
]
}
]
}
}
}
}
Loading…
Cancel
Save