Use the right auth tokens for handshake pairing in tests
This commit is contained in:
parent
bdab3b5ef5
commit
bcdb66cb0e
@ -148,6 +148,9 @@ func TestSuccessfulNodePairing(t *testing.T) {
|
||||
init: func(ctx context.Context, n *types.Node, authToken string) error {
|
||||
h.apiInit().
|
||||
//Debug().
|
||||
// make sure we do not use test auth-token for authentication but
|
||||
// we do it with pairing token
|
||||
Intercept(helpers.ReqHeaderAuthBearer(nil)).
|
||||
Post(fmt.Sprintf("/nodes/%d/handshake", n.SharedNodeID)).
|
||||
FormData("pairToken", n.PairToken).
|
||||
FormData("authToken", authToken).
|
||||
@ -181,6 +184,9 @@ func TestSuccessfulNodePairing(t *testing.T) {
|
||||
complete: func(ctx context.Context, n *types.Node, authToken string) error {
|
||||
h.apiInit().
|
||||
//Debug().
|
||||
// make sure we do not use test auth-token but
|
||||
// one provided to us in the initial handshake step
|
||||
Intercept(helpers.ReqHeaderRawAuthBearer(n.AuthToken)).
|
||||
Post(fmt.Sprintf("/nodes/%d/handshake-complete", n.SharedNodeID)).
|
||||
FormData("authToken", authToken).
|
||||
Expect(t).
|
||||
|
||||
@ -19,6 +19,16 @@ func BindAuthMiddleware(r chi.Router) {
|
||||
|
||||
func ReqHeaderAuthBearer(user *types.User) apitest.Intercept {
|
||||
return func(req *http.Request) {
|
||||
req.Header.Set("Authorization", "Bearer "+auth.DefaultJwtHandler.Encode(user))
|
||||
if user == nil {
|
||||
req.Header.Del("Authorization")
|
||||
} else {
|
||||
req.Header.Set("Authorization", "Bearer "+auth.DefaultJwtHandler.Encode(user))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ReqHeaderRawAuthBearer(token string) apitest.Intercept {
|
||||
return func(req *http.Request) {
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user