Skip to content

Commit 87a9871

Browse files
author
Petya Koleva
committed
Update integration tests with per project subdomains
1 parent 8300d10 commit 87a9871

5 files changed

Lines changed: 67 additions & 30 deletions

File tree

integration-tests/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export CLIENT_SECRET=<client-secret>
2323
```bash
2424
go test . \
2525
-client-id $CLIENT_ID \
26-
-client-secret $CLIENT_SECRET
26+
-client-secret $CLIENT_SECRET \
27+
-project-domain $PROJECT_DOMAIN
2728
```
2829

2930
### Build and run the test binary
@@ -32,7 +33,8 @@ go test . \
3233
go test -mod=vendor -c -o integration-tests .
3334
./integration-tests \
3435
-client-id $CLIENT_ID \
35-
-client-secret $CLIENT_SECRET
36+
-client-secret $CLIENT_SECRET \
37+
-project-domain $PROJECT_DOMAIN
3638
```
3739

3840
### See flags
@@ -48,5 +50,6 @@ docker run \
4850
--network host \
4951
ghcr.io/miracl/oidc-samples/integration-tests:latest \
5052
--client-id $CLIENT_ID \
51-
--client-secret $CLIENT_SECRET
53+
--client-secret $CLIENT_SECRET \
54+
--project-domain $PROJECT_DOMAIN
5255
```

integration-tests/auth_utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func pass1Request(httpClient *http.Client, identity identity, proof []byte, scop
7171

7272
resp, err := makeRequest(
7373
httpClient,
74-
options.apiURL+"/rps/v2/pass1",
74+
options.projectDomain+"/rps/v2/pass1",
7575
"POST",
7676
payload,
7777
)
@@ -99,7 +99,7 @@ func pass2Request(httpClient *http.Client, identity identity, proof []byte, wid
9999

100100
resp, err := makeRequest(
101101
httpClient,
102-
options.apiURL+"/rps/v2/pass2",
102+
options.projectDomain+"/rps/v2/pass2",
103103
"POST",
104104
payload,
105105
)
@@ -123,7 +123,7 @@ func authenticateRequest(httpClient *http.Client, authOTT string) (authResponse
123123

124124
resp, err := makeRequest(
125125
httpClient,
126-
options.apiURL+"/rps/v2/authenticate",
126+
options.projectDomain+"/rps/v2/authenticate",
127127
"POST",
128128
payload,
129129
)
@@ -147,7 +147,7 @@ func accessRequest(httpClient *http.Client, webOTT string) (accessResponse *acce
147147

148148
resp, err := makeRequest(
149149
httpClient,
150-
options.apiURL+"/rps/v2/access",
150+
options.projectDomain+"/rps/v2/access",
151151
"POST",
152152
payload,
153153
)

integration-tests/main_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import (
1010
var options struct {
1111
clientID string
1212
clientSecret string
13-
projectID string
1413
redirectURL string
15-
apiURL string
14+
projectDomain string
1615
sampleURL string
1716
proxyHost string
1817
proxyPort string
@@ -23,11 +22,10 @@ var options struct {
2322
}
2423

2524
func TestMain(m *testing.M) {
26-
flag.StringVar(&options.clientID, "client-id", "", "the client id for the portal app")
27-
flag.StringVar(&options.clientSecret, "client-secret", "", "the client secret for the portal app")
28-
flag.StringVar(&options.projectID, "project-id", "", "the project id for the portal app")
29-
flag.StringVar(&options.redirectURL, "redirect-url", "http://localhost:8000/login", "the redirect url from the portal app")
30-
flag.StringVar(&options.apiURL, "api-url", "https://api.mpin.io", "the mpin api URL")
25+
flag.StringVar(&options.clientID, "client-id", "", "the client id from your MIRACL Trust Portal application")
26+
flag.StringVar(&options.clientSecret, "client-secret", "", "the client secret from your MIRACL Trust Portal application")
27+
flag.StringVar(&options.redirectURL, "redirect-url", "http://localhost:8000/login", "the redirect url from your MIRACL Trust Portal application")
28+
flag.StringVar(&options.projectDomain, "project-domain", "", "the project domain from your MIRACL Trust Portal application")
3129
flag.StringVar(&options.sampleURL, "sample-url", "http://127.0.0.1:8000", "the sample URL")
3230
flag.StringVar(&options.proxyHost, "proxy-host", "", "Sample's proxy HOST")
3331
flag.StringVar(&options.proxyPort, "proxy-port", "", "Sample's proxy PORT")
@@ -38,6 +36,10 @@ func TestMain(m *testing.M) {
3836

3937
flag.Parse()
4038

39+
if options.projectDomain == "" {
40+
fmt.Println("ERROR: project-domain is missing.\nUse -h flag to see all args.")
41+
}
42+
4143
if options.clientSecret == "" && options.clientID == "" {
4244
fmt.Println("ERROR: client-id and client-secret args are missing.\nUse -h flag to see all args.")
4345
os.Exit(1)

integration-tests/register_utils.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import (
1212
"code.miracl.com/maas/maas/src/lib/gomiracl/wrap"
1313
)
1414

15-
func createSession(httpClient *http.Client, userID string) (*sessionResponse, error) {
15+
func createSession(httpClient *http.Client, projectID, userID string) (*sessionResponse, error) {
1616
sessionRequest := &struct {
1717
ProjectID string `json:"projectId"`
1818
UserID string `json:"userId"`
1919
}{
20-
options.projectID,
20+
projectID,
2121
userID,
2222
}
2323

2424
sessionResp, err := makeRequest(
2525
httpClient,
26-
options.apiURL+"/rps/v2/session",
26+
options.projectDomain+"/rps/v2/session",
2727
http.MethodPost,
2828
sessionRequest,
2929
header{Key: "Content-Type", Value: "application/json"})
@@ -40,9 +40,9 @@ func createSession(httpClient *http.Client, userID string) (*sessionResponse, er
4040
return createSessionResponse, nil
4141
}
4242

43-
func register(httpClient *http.Client, userID, deviceName string, pin int, accessID string) (i identity, err error) {
43+
func register(httpClient *http.Client, projectID, userID, deviceName string, pin int, accessID string) (i identity, err error) {
4444
// Call to /verification endpoint.
45-
verifyURL, err := verificationRequest(httpClient, userID, deviceName, accessID)
45+
verifyURL, err := verificationRequest(httpClient, userID, deviceName, accessID, projectID)
4646
if err != nil {
4747
return identity{}, err
4848
}
@@ -65,6 +65,28 @@ func register(httpClient *http.Client, userID, deviceName string, pin int, acces
6565
return id, nil
6666
}
6767

68+
func getProjectID(httpClient *http.Client) (projectID string, err error) {
69+
resp, err := makeRequest(
70+
httpClient,
71+
options.projectDomain+"/.well-known/project-configuration",
72+
"GET",
73+
nil,
74+
)
75+
if err != nil {
76+
return "", err
77+
}
78+
79+
var projectResponse *struct {
80+
ID string `json:"id"`
81+
}
82+
83+
if err := json.Unmarshal(resp, &projectResponse); err != nil {
84+
return "", err
85+
}
86+
87+
return projectResponse.ID, nil
88+
}
89+
6890
func newIdentity(httpClient *http.Client, userID, deviceName, accessID, activationToken string, pin int) (i identity, err error) {
6991
// Call to /rps/v2/user endpoint.
7092
regResponse, err := registerRequest(httpClient, userID, deviceName, accessID, activationToken)
@@ -103,7 +125,7 @@ func newIdentity(httpClient *http.Client, userID, deviceName, accessID, activati
103125
}, nil
104126
}
105127

106-
func verificationRequest(httpClient *http.Client, userID, deviceName, accessID string) (string, error) {
128+
func verificationRequest(httpClient *http.Client, userID, deviceName, accessID, projectID string) (string, error) {
107129
clientIDAndSecret := options.clientID + ":" + options.clientSecret
108130
authHeaderValue := "Basic " + b64.StdEncoding.EncodeToString([]byte(clientIDAndSecret))
109131

@@ -115,7 +137,7 @@ func verificationRequest(httpClient *http.Client, userID, deviceName, accessID s
115137
Delivery string `json:"delivery"`
116138
Authorization string `json:"-"`
117139
}{
118-
options.projectID,
140+
projectID,
119141
userID,
120142
deviceName,
121143
accessID,
@@ -125,7 +147,7 @@ func verificationRequest(httpClient *http.Client, userID, deviceName, accessID s
125147

126148
resp, err := makeRequest(
127149
httpClient,
128-
options.apiURL+"/verification",
150+
options.projectDomain+"/verification",
129151
"POST",
130152
payload,
131153
header{Key: "Authorization", Value: authHeaderValue},
@@ -158,7 +180,7 @@ func registerRequest(httpClient *http.Client, userID, deviceName, accessID, acti
158180

159181
resp, err := makeRequest(
160182
httpClient,
161-
options.apiURL+"/rps/v2/user",
183+
options.projectDomain+"/rps/v2/user",
162184
"PUT",
163185
payload,
164186
header{Key: "X-MIRACL-CID", Value: "mcl"},
@@ -180,7 +202,7 @@ var errInvalidSignatureResponse = errors.New("invalid signature response")
180202
func signatureRequest(httpClient *http.Client, mpinID, regOTT string) (*signatureResponse, error) {
181203
resp, err := makeRequest(
182204
httpClient,
183-
fmt.Sprintf(options.apiURL+"/rps/v2/signature/%v?regOTT=%v", mpinID, regOTT),
205+
fmt.Sprintf(options.projectDomain+"/rps/v2/signature/%v?regOTT=%v", mpinID, regOTT),
184206
"GET",
185207
nil,
186208
)
@@ -239,7 +261,7 @@ func verificationConfirmation(httpClient *http.Client, userID, code string) (str
239261

240262
resp, err := makeRequest(
241263
httpClient,
242-
options.apiURL+"/verification/confirmation",
264+
options.projectDomain+"/verification/confirmation",
243265
"POST",
244266
payload,
245267
)

integration-tests/sample_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ func TestAuth(t *testing.T) {
2323
},
2424
}
2525

26-
sessionResponse, err := createSession(httpClient, userID)
26+
projectID, err := getProjectID(httpClient)
27+
if err != nil {
28+
t.Fatalf("failed to get project configuration: %v", err.Error())
29+
}
30+
31+
sessionResponse, err := createSession(httpClient, projectID, userID)
2732
if err != nil {
2833
t.Fatalf("failed to create session: %v", err.Error())
2934
}
@@ -35,7 +40,7 @@ func TestAuth(t *testing.T) {
3540

3641
accessID := qrURL.Fragment
3742

38-
identity, err := register(httpClient, userID, deviceName, pin, accessID)
43+
identity, err := register(httpClient, projectID, userID, deviceName, pin, accessID)
3944
if err != nil {
4045
t.Fatalf("Error registering: %v", err)
4146
}
@@ -70,6 +75,11 @@ func TestValidateSignature(t *testing.T) {
7075
},
7176
}
7277

78+
projectID, err := getProjectID(httpClient)
79+
if err != nil {
80+
t.Fatalf("failed to get project configuration: %v", err.Error())
81+
}
82+
7383
client := newSampleClient(options.sampleURL, httpClient)
7484
client.restart(options.restarterHost, options.restarterPort, options.sampleName)
7585

@@ -83,7 +93,7 @@ func TestValidateSignature(t *testing.T) {
8393
deviceName := "The device of " + name
8494
pin := randPIN()
8595

86-
sessionResponse, err := createSession(httpClient, userID)
96+
sessionResponse, err := createSession(httpClient, projectID, userID)
8797
if err != nil {
8898
t.Fatalf("failed to create session: %v", err.Error())
8999
}
@@ -95,7 +105,7 @@ func TestValidateSignature(t *testing.T) {
95105

96106
accessID := qrURL.Fragment
97107

98-
identity, err := register(httpClient, userID, deviceName, pin, accessID)
108+
identity, err := register(httpClient, projectID, userID, deviceName, pin, accessID)
99109
if err != nil {
100110
t.Fatalf("Error registering: %v", err)
101111
}
@@ -126,7 +136,7 @@ func modifySignatureHandler(w http.ResponseWriter, r *http.Request) {
126136

127137
defer r.Body.Close()
128138

129-
const jwksURI = "https://api.mpin.io:443/oidc/certs"
139+
var jwksURI = options.projectDomain + "/oidc/certs"
130140

131141
originalRequestURL := r.Header.Get("X-Forwarded-Host")
132142
if originalRequestURL == jwksURI {

0 commit comments

Comments
 (0)