mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-19 17:50:17 +02:00
Add a new reason "client-certificate-required" that will be returned by the invalid_client_certificate criterion in the case that no client certificate was provided. Determine this using the new 'presented' field populated from the Envoy metadata.
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package criteria
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestInvalidClientCertificate(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
cases := []struct {
|
|
label string
|
|
input Input
|
|
expected A
|
|
}{
|
|
{
|
|
"not presented",
|
|
Input{},
|
|
A{true, A{ReasonClientCertificateRequired}, M{}},
|
|
},
|
|
{
|
|
"invalid",
|
|
Input{
|
|
HTTP: InputHTTP{
|
|
ClientCertificate: ClientCertificateInfo{Presented: true},
|
|
},
|
|
},
|
|
A{true, A{ReasonInvalidClientCertificate}, M{}},
|
|
},
|
|
{
|
|
"valid",
|
|
Input{
|
|
HTTP: InputHTTP{
|
|
ClientCertificate: ClientCertificateInfo{Presented: true},
|
|
},
|
|
IsValidClientCertificate: true,
|
|
},
|
|
A{false, A{ReasonValidClientCertificate}, M{}},
|
|
},
|
|
}
|
|
|
|
const policy = `
|
|
deny:
|
|
or:
|
|
- invalid_client_certificate: true`
|
|
|
|
for i := range cases {
|
|
c := cases[i]
|
|
t.Run(c.label, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
res, err := evaluate(t, policy, []dataBrokerRecord{}, c.input)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, A{false, A{}}, res["allow"])
|
|
assert.Equal(t, c.expected, res["deny"])
|
|
})
|
|
}
|
|
}
|