mirror of
https://github.com/openziti/ziti.git
synced 2026-10-12 23:32:02 +00:00
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
//go:build apitests
|
|
|
|
package tests
|
|
|
|
import (
|
|
"github.com/openziti/foundation/identity/identity"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func Test_TestAuthNoCert(t *testing.T) {
|
|
ctx := NewTestContext(t)
|
|
defer ctx.Teardown()
|
|
ctx.StartServer()
|
|
ctx.requireRestPort(5 * time.Second)
|
|
|
|
client := ctx.NewRestClient(nil)
|
|
resp, err := client.R().Get("https://localhost:1281/fabric/v1/services")
|
|
ctx.Req.True(err != nil || resp.IsError())
|
|
}
|
|
|
|
func Test_TestAuthWithCertFromDifferentChain(t *testing.T) {
|
|
ctx := NewTestContext(t)
|
|
defer ctx.Teardown()
|
|
ctx.StartServer()
|
|
ctx.requireRestPort(5 * time.Second)
|
|
|
|
badId, err := identity.LoadClientIdentity(
|
|
"./testdata/invalid_client_cert/client.cert",
|
|
"./testdata/invalid_client_cert/client.key",
|
|
"./testdata/ca/intermediate/certs/ca-chain.cert.pem")
|
|
ctx.Req.NoError(err)
|
|
|
|
client := ctx.NewRestClient(badId)
|
|
resp, err := client.R().Get("https://localhost:1281/fabric/v1/services")
|
|
ctx.Req.NoError(err)
|
|
ctx.Req.Equal(http.StatusUnauthorized, resp.StatusCode())
|
|
}
|
|
|
|
func Test_ListServicesWithValidCert(t *testing.T) {
|
|
ctx := NewTestContext(t)
|
|
defer ctx.Teardown()
|
|
ctx.StartServer()
|
|
ctx.requireRestPort(5 * time.Second)
|
|
client := ctx.NewRestClientWithDefaults()
|
|
resp, err := client.R().Get("https://localhost:1281/fabric/v1/services")
|
|
ctx.Req.NoError(err)
|
|
ctx.Req.True(resp.IsSuccess())
|
|
}
|