-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathrest_auth_test.go
55 lines (45 loc) · 1.47 KB
/
rest_auth_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//go:build apitests
package tests
import (
idlib "github.com/openziti/identity"
"net/http"
"testing"
)
func Test_TestAuthWithCertFromDifferentChain(t *testing.T) {
ctx := NewTestContext(t)
defer ctx.Teardown()
ctx.StartServer()
badId, err := idlib.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()
id, err := idlib.LoadClientIdentity(
"./testdata/valid_client_cert/client.cert",
"./testdata/valid_client_cert/client.key",
"./testdata/ca/intermediate/certs/ca-chain.cert.pem")
ctx.Req.NoError(err)
client := ctx.NewRestClient(id)
resp, err := client.R().Get("https://localhost:1281/fabric/v1/services")
ctx.Req.NoError(err)
ctx.Req.Equal(http.StatusUnauthorized, resp.StatusCode())
}
func Test_ListServicesWithEdgeAuth(t *testing.T) {
ctx := NewTestContext(t)
defer ctx.Teardown()
ctx.StartServer()
ctx.RequireAdminManagementApiLogin()
req := ctx.AdminManagementSession.newAuthenticatedRequest()
resp, err := req.Get("https://localhost:1281/fabric/v1/services")
ctx.Req.NoError(err)
ctx.Req.True(resp.IsSuccess())
}