2022-12-31 10:22:38 +01:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-01-30 19:59:42 +01:00
|
|
|
"github.com/twofas/2fas-server/tests"
|
2022-12-31 10:22:38 +01:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_GetPending2FaRequests(t *testing.T) {
|
|
|
|
device, devicePubKey := tests.CreateDevice(t, "SM-955F", "fcm-token")
|
|
|
|
browserExtension := tests.CreateBrowserExtension(t, "go-ext")
|
|
|
|
tests.PairDeviceWithBrowserExtension(t, devicePubKey, browserExtension, device)
|
|
|
|
|
|
|
|
var tokenRequest *tests.AuthTokenRequestResponse
|
|
|
|
request2FaTokenPayload := []byte(`{"domain":"domain.com"}`)
|
|
|
|
tests.DoSuccessPost(t, "browser_extensions/"+browserExtension.Id+"/commands/request_2fa_token", request2FaTokenPayload, &tokenRequest)
|
|
|
|
|
|
|
|
var tokenRequestsCollection []*tests.AuthTokenRequestResponse
|
|
|
|
tests.DoSuccessGet(t, "mobile/devices/"+device.Id+"/browser_extensions/2fa_requests", &tokenRequestsCollection)
|
|
|
|
assert.Len(t, tokenRequestsCollection, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_DoNotReturnCompleted2FaRequests(t *testing.T) {
|
|
|
|
device, devicePubKey := tests.CreateDevice(t, "SM-955F", "fcm-token")
|
|
|
|
browserExtension := tests.CreateBrowserExtension(t, "go-ext")
|
|
|
|
tests.PairDeviceWithBrowserExtension(t, devicePubKey, browserExtension, device)
|
|
|
|
|
|
|
|
var tokenRequest *tests.AuthTokenRequestResponse
|
|
|
|
request2FaTokenPayload := []byte(`{"domain":"domain.com"}`)
|
|
|
|
tests.DoSuccessPost(t, "browser_extensions/"+browserExtension.Id+"/commands/request_2fa_token", request2FaTokenPayload, &tokenRequest)
|
|
|
|
|
|
|
|
closeTokenRequestPayload := []byte(`{"status":"completed"}`)
|
|
|
|
tests.DoSuccessPost(t, "browser_extensions/"+browserExtension.Id+"/2fa_requests/"+tokenRequest.Id+"/commands/close_2fa_request", closeTokenRequestPayload, nil)
|
|
|
|
|
|
|
|
var tokenRequestsCollection []*tests.AuthTokenRequestResponse
|
|
|
|
tests.DoSuccessGet(t, "mobile/devices/"+device.Id+"/browser_extensions/2fa_requests", &tokenRequestsCollection)
|
|
|
|
assert.Len(t, tokenRequestsCollection, 0)
|
|
|
|
}
|