test suite for mobile all extension tests

This commit is contained in:
in-void 2023-03-12 15:00:34 +01:00
parent 8cdc2f3593
commit 9745ffa796

View File

@ -2,37 +2,52 @@ package tests
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/tests"
"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 TestMobileDeviceExtensionIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(MobileDeviceExtensionIntegrationTestSuite))
}
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)
type MobileDeviceExtensionIntegrationTestSuite struct {
suite.Suite
}
func (s *MobileDeviceExtensionIntegrationTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "browser_extensions")
tests.DoSuccessDelete(s.T(), "mobile/devices")
tests.DoSuccessDelete(s.T(), "browser_extensions/devices")
}
func (s *MobileDeviceExtensionIntegrationTestSuite) TestGetPending2FaRequests() {
device, devicePubKey := tests.CreateDevice(s.T(), "SM-955F", "fcm-token")
browserExtension := tests.CreateBrowserExtension(s.T(), "go-ext")
tests.PairDeviceWithBrowserExtension(s.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)
tests.DoSuccessPost(s.T(), "browser_extensions/"+browserExtension.Id+"/commands/request_2fa_token", request2FaTokenPayload, &tokenRequest)
var tokenRequestsCollection []*tests.AuthTokenRequestResponse
tests.DoSuccessGet(s.T(), "mobile/devices/"+device.Id+"/browser_extensions/2fa_requests", &tokenRequestsCollection)
assert.Len(s.T(), tokenRequestsCollection, 1)
}
func (s *MobileDeviceExtensionIntegrationTestSuite) TestDoNotReturnCompleted2FaRequests() {
device, devicePubKey := tests.CreateDevice(s.T(), "SM-955F", "fcm-token")
browserExtension := tests.CreateBrowserExtension(s.T(), "go-ext")
tests.PairDeviceWithBrowserExtension(s.T(), devicePubKey, browserExtension, device)
var tokenRequest *tests.AuthTokenRequestResponse
request2FaTokenPayload := []byte(`{"domain":"domain.com"}`)
tests.DoSuccessPost(s.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)
tests.DoSuccessPost(s.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)
tests.DoSuccessGet(s.T(), "mobile/devices/"+device.Id+"/browser_extensions/2fa_requests", &tokenRequestsCollection)
assert.Len(s.T(), tokenRequestsCollection, 0)
}