Fix e2e tests after separating admin api

This commit is contained in:
tobiasz 2023-10-19 14:12:16 +02:00
parent 6089495167
commit 908f9f4f93
20 changed files with 294 additions and 120 deletions

View File

@ -9,15 +9,16 @@ help:
migration: ## create database migrations file
docker-compose run -u ${USERID}:${USERID} --rm api migrate create new_migration sql
docker compose run -u ${USERID}:${USERID} --rm api migrate create new_migration sql
migration-up: ## apply all available migrations
docker-compose run -u ${USERID}:${USERID} --rm api migrate up
docker compose run -u ${USERID}:${USERID} --rm api migrate up
up: ## run all applications in stack
docker-compose up -d
docker compose build
docker compose up -d
test: ## run unit tests

View File

@ -6,11 +6,16 @@ services:
context: .
dockerfile: docker/api/Dockerfile
depends_on:
shared-volume-init:
condition: service_completed_successfully
mysql:
condition: service_healthy
group_add:
- '1000'
volumes:
- ./migrations:/migrations
- go-modules:/go/pkg/mod
- shared-volume:/tmp/2fas
ports:
- "80:8080"
env_file:
@ -21,8 +26,14 @@ services:
context: .
dockerfile: docker/admin/Dockerfile
depends_on:
shared-volume-init:
condition: service_completed_successfully
mysql:
condition: service_healthy
group_add:
- '1000'
volumes:
- shared-volume:/tmp/2fas
ports:
- "8082:8080"
env_file:
@ -69,5 +80,21 @@ services:
volumes:
- ./api/openapi:/usr/share/nginx/html/doc
# docker compose always mount named volumes as root (https://github.com/docker/compose/issues/3270)
# and without changing permission, we want be able to access shared volume
shared-volume-init:
image: ubuntu
user: root
group_add:
- '1000'
volumes:
- shared-volume:/tmp/2fas
command: chown -R 1000:1000 /tmp/2fas
volumes:
go-modules:
# shared-volume is used to share volume between api and admin. On producition AWS S3 is used,
# but here for local dev shared volume is fine.
shared-volume:

View File

@ -148,12 +148,11 @@ func (m *BrowserExtensionModule) RegisterPublicRoutes(router *gin.Engine) {
publicRouter.GET("/browser_extensions/:extension_id/2fa_requests/:token_request_id", m.RoutesHandler.GetBrowserExtension2FaTokenRequest)
publicRouter.POST("/browser_extensions/:extension_id/2fa_requests/:token_request_id/commands/close_2fa_request", m.RoutesHandler.Close2FaRequest)
}
func (m *BrowserExtensionModule) RegisterAdminRoutes(g *gin.RouterGroup) {
if m.Config.IsTestingEnv() {
publicRouter.DELETE("/browser_extensions", m.RoutesHandler.RemoveAllBrowserExtensions)
publicRouter.DELETE("/browser_extensions/devices", m.RoutesHandler.RemoveAllBrowserExtensionsDevices)
g.DELETE("/browser_extensions", m.RoutesHandler.RemoveAllBrowserExtensions)
g.DELETE("/browser_extensions/devices", m.RoutesHandler.RemoveAllBrowserExtensionsDevices)
}
}
func (m *BrowserExtensionModule) RegisterAdminRoutes(g *gin.RouterGroup) {
}

View File

@ -19,7 +19,7 @@ type TmpFileSystem struct {
}
func NewTmpFileSystem() FileSystemStorage {
tmpDir := "/tmp"
tmpDir := "/tmp/2fas"
return &TmpFileSystem{
baseDirectory: tmpDir,

View File

@ -1,11 +1,12 @@
package tests
import (
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/tests"
"testing"
)
func TestBrowserExtensionTwoFactorAuthTestSuite(t *testing.T) {
@ -17,9 +18,9 @@ type BrowserExtensionTwoFactorAuthTestSuite struct {
}
func (s *BrowserExtensionTwoFactorAuthTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "/mobile/devices")
tests.DoSuccessDelete(s.T(), "/browser_extensions")
tests.DoSuccessDelete(s.T(), "browser_extensions/devices")
tests.RemoveAllMobileDevices(s.T())
tests.RemoveAllBrowserExtensions(s.T())
tests.RemoveAllBrowserExtensionsDevices(s.T())
}
func (s *BrowserExtensionTwoFactorAuthTestSuite) TestRequest2FaToken() {

View File

@ -2,10 +2,11 @@ package tests
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/tests"
"testing"
)
func TestTwoFactorAuthTestSuite(t *testing.T) {
@ -17,9 +18,9 @@ type TwoFactorAuthTestSuite struct {
}
func (s *TwoFactorAuthTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "/mobile/devices")
tests.DoSuccessDelete(s.T(), "/browser_extensions")
tests.DoSuccessDelete(s.T(), "browser_extensions/devices")
tests.RemoveAllMobileDevices(s.T())
tests.RemoveAllBrowserExtensions(s.T())
tests.RemoveAllBrowserExtensionsDevices(s.T())
}
func (s *TwoFactorAuthTestSuite) TestBrowserExtensionAuthFullFlow() {

View File

@ -2,12 +2,13 @@ package tests
import (
"encoding/json"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/tests"
"testing"
)
func TestBrowserExtensionPairingTestSuite(t *testing.T) {
@ -19,8 +20,8 @@ type BrowserExtensionPairingTestSuite struct {
}
func (s *BrowserExtensionPairingTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "browser_extensions")
tests.DoSuccessDelete(s.T(), "browser_extensions/devices")
tests.RemoveAllBrowserExtensions(s.T())
tests.RemoveAllBrowserExtensionsDevices(s.T())
}
func (s *BrowserExtensionPairingTestSuite) TestPairBrowserExtensionWithMobileDevice() {

View File

@ -2,13 +2,14 @@ package tests
import (
"fmt"
"net/http"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/internal/common/crypto"
"github.com/twofas/2fas-server/tests"
"net/http"
"testing"
)
func TestBrowserExtensionTestSuite(t *testing.T) {
@ -20,7 +21,7 @@ type BrowserExtensionTestSuite struct {
}
func (s *BrowserExtensionTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "/browser_extensions")
tests.RemoveAllBrowserExtensions(s.T())
}
func (s *BrowserExtensionTestSuite) TestCreateBrowserExtension() {

View File

@ -3,8 +3,9 @@ package tests
import (
"encoding/json"
"fmt"
"github.com/twofas/2fas-server/internal/common/crypto"
"testing"
"github.com/twofas/2fas-server/internal/common/crypto"
)
func CreateDevice(t *testing.T, name, fcmToken string) (*DeviceResponse, string) {
@ -87,3 +88,35 @@ func Send2FaTokenToExtension(t *testing.T, extensionId, deviceId, requestId, tok
DoSuccessPost(t, "mobile/devices/"+deviceId+"/commands/send_2fa_token", []byte(j), nil)
}
func RemoveAllBrowserExtensionsDevices(t *testing.T) {
DoSuccessDeleteAdmin(t, "browser_extensions/devices")
}
func RemoveAllBrowserExtensions(t *testing.T) {
DoSuccessDeleteAdmin(t, "browser_extensions")
}
func RemoveAllMobileDevices(t *testing.T) {
DoSuccessDeleteAdmin(t, "/mobile/devices")
}
func RemoveAllMobileIconsCollections(t *testing.T) {
DoSuccessDeleteAdmin(t, "mobile/icons/collections")
}
func RemoveAllMobileWebServices(t *testing.T) {
DoSuccessDeleteAdmin(t, "mobile/web_services")
}
func RemoveAllMobileIcons(t *testing.T) {
DoSuccessDeleteAdmin(t, "mobile/icons")
}
func RemoveAllMobileIconsRequests(t *testing.T) {
DoSuccessDeleteAdmin(t, "mobile/icons/requests")
}
func RemoveAllMobileNotifications(t *testing.T) {
DoSuccessDeleteAdmin(t, "mobile/notifications")
}

View File

@ -5,7 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"testing"
@ -14,7 +14,10 @@ import (
"github.com/stretchr/testify/require"
)
const DebugHttpRequests = false
const (
DebugHttpRequests = false
adminRawURL = "http://localhost:8082/admin"
)
var baseUrl *url.URL
var Auth *BasicAuth
@ -42,7 +45,7 @@ func DoSuccessPost(t *testing.T, uri string, payload []byte, resp interface{}) {
logRequest(request, response)
rawBody, _ := ioutil.ReadAll(response.Body)
rawBody, _ := io.ReadAll(response.Body)
if resp != nil {
responseDataReader := bytes.NewReader(rawBody)
@ -52,6 +55,27 @@ func DoSuccessPost(t *testing.T, uri string, payload []byte, resp interface{}) {
require.Equal(t, 200, response.StatusCode)
}
func DoSuccessPostAdmin(t *testing.T, uri string, payload []byte, resp interface{}) {
adminURL, err := url.Parse(adminRawURL)
require.NoError(t, err)
request := createRequest(http.MethodPost, adminURL.JoinPath(uri).String(), payload)
response, err := http.DefaultClient.Do(request)
require.NoError(t, err)
logRequest(request, response)
rawBody, err := io.ReadAll(response.Body)
require.NoError(t, err)
if resp != nil {
responseDataReader := bytes.NewReader(rawBody)
err = json.NewDecoder(responseDataReader).Decode(resp)
require.NoError(t, err)
}
require.Equal(t, 200, response.StatusCode)
}
func DoPost(uri string, payload []byte, resp interface{}) *http.Response {
u, _ := baseUrl.Parse(uri)
@ -60,7 +84,7 @@ func DoPost(uri string, payload []byte, resp interface{}) *http.Response {
logRequest(request, response)
rawBody, _ := ioutil.ReadAll(response.Body)
rawBody, _ := io.ReadAll(response.Body)
if resp != nil {
responseDataReader := bytes.NewReader(rawBody)
@ -68,11 +92,56 @@ func DoPost(uri string, payload []byte, resp interface{}) *http.Response {
}
response.Body.Close()
response.Body = ioutil.NopCloser(bytes.NewBuffer(rawBody))
response.Body = io.NopCloser(bytes.NewBuffer(rawBody))
return response
}
func DoPostAdmin(t *testing.T, uri string, payload []byte, resp interface{}) *http.Response {
adminURL, err := url.Parse(adminRawURL)
require.NoError(t, err)
request := createRequest(http.MethodPost, adminURL.JoinPath(uri).String(), payload)
response, err := http.DefaultClient.Do(request)
require.NoError(t, err)
logRequest(request, response)
rawBody, err := io.ReadAll(response.Body)
require.NoError(t, err)
if resp != nil {
responseDataReader := bytes.NewReader(rawBody)
err = json.NewDecoder(responseDataReader).Decode(resp)
require.NoError(t, err)
}
response.Body.Close()
response.Body = io.NopCloser(bytes.NewBuffer(rawBody))
return response
}
func DoSuccessPutAdmin(t *testing.T, uri string, payload []byte, resp interface{}) {
adminURL, err := url.Parse(adminRawURL)
require.NoError(t, err)
request := createRequest(http.MethodPut, adminURL.JoinPath(uri).String(), payload)
response, err := http.DefaultClient.Do(request)
require.NoError(t, err)
logRequest(request, response)
rawBody, err := io.ReadAll(response.Body)
require.NoError(t, err)
if resp != nil {
responseDataReader := bytes.NewReader(rawBody)
err = json.NewDecoder(responseDataReader).Decode(resp)
require.NoError(t, err)
}
require.Equal(t, 200, response.StatusCode)
}
func DoSuccessPut(t *testing.T, uri string, payload []byte, resp interface{}) {
u, _ := baseUrl.Parse(uri)
@ -82,7 +151,7 @@ func DoSuccessPut(t *testing.T, uri string, payload []byte, resp interface{}) {
logRequest(request, response)
rawBody, _ := ioutil.ReadAll(response.Body)
rawBody, _ := io.ReadAll(response.Body)
if resp != nil {
responseDataReader := bytes.NewReader(rawBody)
@ -100,7 +169,7 @@ func DoPut(uri string, payload []byte, resp interface{}) *http.Response {
logRequest(request, response)
rawBody, _ := ioutil.ReadAll(response.Body)
rawBody, _ := io.ReadAll(response.Body)
if resp != nil {
responseDataReader := bytes.NewReader(rawBody)
@ -117,7 +186,7 @@ func DoSuccessGet(t *testing.T, uri string, resp interface{}) {
response, err := http.DefaultClient.Do(request)
require.NoError(t, err)
rawBody, _ := ioutil.ReadAll(response.Body)
rawBody, _ := io.ReadAll(response.Body)
logRequest(request, response)
@ -128,16 +197,34 @@ func DoSuccessGet(t *testing.T, uri string, resp interface{}) {
require.NoError(t, err)
}
func DoSuccessGetAdmin(t *testing.T, uri string, resp interface{}) {
adminURL, err := url.Parse(adminRawURL)
require.NoError(t, err)
request := createRequest(http.MethodGet, adminURL.JoinPath(uri).String(), nil)
response, err := http.DefaultClient.Do(request)
require.NoError(t, err)
rawBody, err := io.ReadAll(response.Body)
require.NoError(t, err)
logRequest(request, response)
require.Equal(t, 200, response.StatusCode)
err = json.Unmarshal(rawBody, resp)
require.NoError(t, err)
}
func DoGet(uri string, resp interface{}) *http.Response {
u, _ := baseUrl.Parse(uri)
request := createRequest(http.MethodGet, u.String(), nil)
response, _ := http.DefaultClient.Do(request)
rawBody, _ := ioutil.ReadAll(response.Body)
rawBody, _ := io.ReadAll(response.Body)
response.Body.Close()
response.Body = ioutil.NopCloser(bytes.NewBuffer(rawBody))
response.Body = io.NopCloser(bytes.NewBuffer(rawBody))
logRequest(request, response)
@ -146,6 +233,19 @@ func DoGet(uri string, resp interface{}) *http.Response {
return response
}
func DoSuccessDeleteAdmin(t *testing.T, uri string) *http.Response {
adminURL, err := url.Parse(adminRawURL)
require.NoError(t, err)
request := createRequest(http.MethodDelete, adminURL.JoinPath(uri).String(), nil)
response, err := http.DefaultClient.Do(request)
require.NoError(t, err)
logRequest(request, response)
require.Equal(t, 200, response.StatusCode)
return response
}
func DoSuccessDelete(t *testing.T, uri string) *http.Response {
u, _ := baseUrl.Parse(uri)
@ -185,10 +285,10 @@ func createRequest(method, uri string, payload []byte) *http.Request {
func logRequest(req *http.Request, resp *http.Response) {
if DebugHttpRequests {
rawBody, _ := ioutil.ReadAll(resp.Body)
rawBody, _ := io.ReadAll(resp.Body)
resp.Body.Close()
resp.Body = ioutil.NopCloser(bytes.NewBuffer(rawBody))
resp.Body = io.NopCloser(bytes.NewBuffer(rawBody))
fmt.Printf("Request: %s: %s %v \n", req.Method, req.URL.RequestURI(), req.Body)
fmt.Println("Response: ", req.URL.RequestURI(), resp.StatusCode, string(rawBody))

View File

@ -1,10 +1,11 @@
package tests
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/tests"
"testing"
)
type iconsCollectionResponse struct {
@ -25,7 +26,7 @@ type IconsCollectionsTestSuite struct {
}
func (s *IconsCollectionsTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "mobile/icons/collections")
tests.RemoveAllMobileIconsCollections(s.T())
}
func (s *IconsCollectionsTestSuite) TestCreateIconsCollection() {
@ -38,7 +39,7 @@ func (s *IconsCollectionsTestSuite) TestCreateIconsCollection() {
`)
var IconsCollection *iconsCollectionResponse
tests.DoSuccessPost(s.T(), "mobile/icons/collections", payload, &IconsCollection)
tests.DoSuccessPostAdmin(s.T(), "mobile/icons/collections", payload, &IconsCollection)
assert.Equal(s.T(), "facebook", IconsCollection.Name)
assert.Equal(s.T(), "desc", IconsCollection.Description)
@ -54,7 +55,7 @@ func (s *IconsCollectionsTestSuite) TestUpdateIconsCollection() {
}
`)
var iconsCollection *iconsCollectionResponse
tests.DoSuccessPost(s.T(), "mobile/icons/collections", payload, &iconsCollection)
tests.DoSuccessPostAdmin(s.T(), "mobile/icons/collections", payload, &iconsCollection)
updatePayload := []byte(`
{
@ -64,7 +65,7 @@ func (s *IconsCollectionsTestSuite) TestUpdateIconsCollection() {
`)
var updatedIconsCollection *iconsCollectionResponse
tests.DoSuccessPut(s.T(), "mobile/icons/collections/"+iconsCollection.Id, updatePayload, &updatedIconsCollection)
tests.DoSuccessPutAdmin(s.T(), "mobile/icons/collections/"+iconsCollection.Id, updatePayload, &updatedIconsCollection)
assert.Equal(s.T(), "meta", updatedIconsCollection.Name)
assert.Equal(s.T(), []string{"icon-1", "icon-2"}, updatedIconsCollection.Icons)
@ -78,9 +79,9 @@ func (s *IconsCollectionsTestSuite) TestDeleteIconsCollection() {
}
`)
var iconsCollection *iconsCollectionResponse
tests.DoSuccessPost(s.T(), "mobile/icons/collections", payload, &iconsCollection)
tests.DoSuccessPostAdmin(s.T(), "mobile/icons/collections", payload, &iconsCollection)
tests.DoSuccessDelete(s.T(), "mobile/icons/collections/"+iconsCollection.Id)
tests.DoSuccessDeleteAdmin(s.T(), "mobile/icons/collections/"+iconsCollection.Id)
response := tests.DoGet("mobile/icons/collections/"+iconsCollection.Id, nil)
assert.Equal(s.T(), 404, response.StatusCode)
@ -93,7 +94,7 @@ func (s *IconsCollectionsTestSuite) TestFindAllIconsCollections() {
"icons":["icon-1", "icon-2"]
}
`)
tests.DoSuccessPost(s.T(), "mobile/icons/collections", payload, nil)
tests.DoSuccessPostAdmin(s.T(), "mobile/icons/collections", payload, nil)
payload2 := []byte(`
{
@ -102,7 +103,7 @@ func (s *IconsCollectionsTestSuite) TestFindAllIconsCollections() {
"icons":["123e4567-e89b-12d3-a456-426614174000"]
}
`)
tests.DoSuccessPost(s.T(), "mobile/icons/collections", payload2, nil)
tests.DoSuccessPostAdmin(s.T(), "mobile/icons/collections", payload2, nil)
var IconsCollections []*iconsCollectionResponse
tests.DoSuccessGet(s.T(), "mobile/icons/collections", &IconsCollections)
@ -118,7 +119,7 @@ func (s *IconsCollectionsTestSuite) TestFindIconsCollection() {
}
`)
var createdIconsCollection *iconsCollectionResponse
tests.DoSuccessPost(s.T(), "mobile/icons/collections", payload, &createdIconsCollection)
tests.DoSuccessPostAdmin(s.T(), "mobile/icons/collections", payload, &createdIconsCollection)
var IconsCollection *iconsCollectionResponse
tests.DoSuccessGet(s.T(), "mobile/icons/collections/"+createdIconsCollection.Id, &IconsCollection)

View File

@ -2,13 +2,14 @@ package tests
import (
"encoding/base64"
"io/ioutil"
"testing"
"github.com/jaswdr/faker"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/internal/api/icons/app/queries"
"github.com/twofas/2fas-server/tests"
"io/ioutil"
"testing"
)
func TestIconsRequestsTestSuite(t *testing.T) {
@ -20,10 +21,10 @@ type IconsRequestsTestSuite struct {
}
func (s *IconsRequestsTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "mobile/web_services")
tests.DoSuccessDelete(s.T(), "mobile/icons")
tests.DoSuccessDelete(s.T(), "mobile/icons/collections")
tests.DoSuccessDelete(s.T(), "mobile/icons/requests")
tests.RemoveAllMobileWebServices(s.T())
tests.RemoveAllMobileIcons(s.T())
tests.RemoveAllMobileIconsCollections(s.T())
tests.RemoveAllMobileIconsRequests(s.T())
}
func (s *IconsRequestsTestSuite) TestCreateIconRequest() {
@ -64,7 +65,7 @@ func (s *IconsRequestsTestSuite) TestCreateIconRequestWithNotAllowedIconDimensio
func (s *IconsRequestsTestSuite) TestDeleteIconRequest() {
iconRequest := createIconRequest(s.T(), "service")
tests.DoSuccessDelete(s.T(), "mobile/icons/requests/"+iconRequest.Id)
tests.DoSuccessDeleteAdmin(s.T(), "mobile/icons/requests/"+iconRequest.Id)
response := tests.DoGet("mobile/icons/requests/"+iconRequest.Id, nil)
assert.Equal(s.T(), 404, response.StatusCode)
@ -84,7 +85,7 @@ func (s *IconsRequestsTestSuite) TestFindIconRequest() {
iconRequest := createIconRequest(s.T(), "service")
var searchResult *queries.IconPresenter
tests.DoSuccessGet(s.T(), "mobile/icons/requests/"+iconRequest.Id, &searchResult)
tests.DoSuccessGetAdmin(s.T(), "mobile/icons/requests/"+iconRequest.Id, &searchResult)
assert.Equal(s.T(), "service", searchResult.Name)
}
@ -93,7 +94,7 @@ func (s *IconsRequestsTestSuite) TestTransformIconRequestIntoWebService() {
iconRequest := createIconRequest(s.T(), "service")
var result *queries.WebServicePresenter
tests.DoSuccessPost(s.T(), "mobile/icons/requests/"+iconRequest.Id+"/commands/transform_to_web_service", nil, &result)
tests.DoSuccessPostAdmin(s.T(), "mobile/icons/requests/"+iconRequest.Id+"/commands/transform_to_web_service", nil, &result)
assert.Equal(s.T(), "service", result.Name)
}
@ -103,7 +104,7 @@ func (s *IconsRequestsTestSuite) TestTransformSingleIconRequestsIntoWebServiceFr
createIconRequest(s.T(), "service")
var result *queries.WebServicePresenter
tests.DoSuccessPost(s.T(), "mobile/icons/requests/"+iconRequest.Id+"/commands/transform_to_web_service", nil, &result)
tests.DoSuccessPostAdmin(s.T(), "mobile/icons/requests/"+iconRequest.Id+"/commands/transform_to_web_service", nil, &result)
var icons []*queries.IconPresenter
tests.DoGet("mobile/icons", &icons)
@ -116,7 +117,7 @@ func (s *IconsRequestsTestSuite) TestTransformIconRequestWithAlreadyExistingWebS
iconRequest := createIconRequest(s.T(), webService.Name)
var result *queries.WebServicePresenter
response := tests.DoPost("mobile/icons/requests/"+iconRequest.Id+"/commands/transform_to_web_service", nil, &result)
response := tests.DoPostAdmin(s.T(), "mobile/icons/requests/"+iconRequest.Id+"/commands/transform_to_web_service", nil, &result)
assert.Equal(s.T(), 409, response.StatusCode)
}
@ -127,7 +128,7 @@ func (s *IconsRequestsTestSuite) TestUpdateWebServiceFromIconRequest() {
var result *queries.WebServicePresenter
payload := []byte(`{"web_service_id":"` + webService.Id + `"}`)
tests.DoSuccessPost(s.T(), "mobile/icons/requests/"+iconRequest.Id+"/commands/update_web_service", payload, &result)
tests.DoSuccessPostAdmin(s.T(), "mobile/icons/requests/"+iconRequest.Id+"/commands/update_web_service", payload, &result)
assert.Equal(s.T(), webService.Name, result.Name)
}

View File

@ -2,13 +2,14 @@ package tests
import (
"encoding/base64"
"io/ioutil"
"testing"
"github.com/jaswdr/faker"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
query "github.com/twofas/2fas-server/internal/api/icons/app/queries"
"github.com/twofas/2fas-server/tests"
"io/ioutil"
"testing"
)
func createIcon(t *testing.T) *query.IconPresenter {
@ -33,7 +34,7 @@ func createIcon(t *testing.T) *query.IconPresenter {
var icon *query.IconPresenter
tests.DoSuccessPost(t, "mobile/icons", payload, &icon)
tests.DoSuccessPostAdmin(t, "mobile/icons", payload, &icon)
return icon
}
@ -47,7 +48,7 @@ type IconsTestSuite struct {
}
func (s *IconsTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "mobile/icons")
tests.DoSuccessDeleteAdmin(s.T(), "mobile/icons")
}
func (s *IconsTestSuite) TestCreateIcon() {
@ -66,7 +67,7 @@ func (s *IconsTestSuite) TestUpdateIcon() {
`)
var updatedIcon *query.IconPresenter
tests.DoSuccessPut(s.T(), "mobile/icons/"+icon.Id, updatePayload, &updatedIcon)
tests.DoSuccessPutAdmin(s.T(), "mobile/icons/"+icon.Id, updatePayload, &updatedIcon)
assert.Equal(s.T(), "meta", updatedIcon.Name)
}
@ -74,7 +75,7 @@ func (s *IconsTestSuite) TestUpdateIcon() {
func (s *IconsTestSuite) TestDeleteIcon() {
icon := createIcon(s.T())
tests.DoSuccessDelete(s.T(), "mobile/icons/"+icon.Id)
tests.DoSuccessDeleteAdmin(s.T(), "mobile/icons/"+icon.Id)
response := tests.DoGet("mobile/icons/"+icon.Id, nil)
assert.Equal(s.T(), 404, response.StatusCode)

View File

@ -2,11 +2,12 @@ package tests
import (
"fmt"
"math/rand"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/tests"
"math/rand"
"testing"
)
func TestWebServicesDumpTestSuite(t *testing.T) {
@ -18,9 +19,9 @@ type WebServicesDumpTestSuite struct {
}
func (s *WebServicesDumpTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "mobile/icons")
tests.DoSuccessDelete(s.T(), "mobile/icons/collections")
tests.DoSuccessDelete(s.T(), "mobile/web_services")
tests.RemoveAllMobileIcons(s.T())
tests.RemoveAllMobileIconsCollections(s.T())
tests.RemoveAllMobileWebServices(s.T())
}
func (s *WebServicesDumpTestSuite) TestWebServicesDump() {
@ -47,7 +48,7 @@ func createWebService(t *testing.T) *webServiceResponse {
var webService *webServiceResponse
tests.DoSuccessPost(t, "mobile/web_services", payload, &webService)
tests.DoSuccessPostAdmin(t, "mobile/web_services", payload, &webService)
return webService
}
@ -65,7 +66,7 @@ func createIconsCollection(t *testing.T) *iconsCollectionResponse {
var createdIconsCollection *iconsCollectionResponse
tests.DoSuccessPost(t, "mobile/icons/collections", payload, &createdIconsCollection)
tests.DoSuccessPostAdmin(t, "mobile/icons/collections", payload, &createdIconsCollection)
return createdIconsCollection
}

View File

@ -1,11 +1,12 @@
package tests
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/internal/api/icons/app/command"
"github.com/twofas/2fas-server/tests"
"testing"
)
type webServiceResponse struct {
@ -29,7 +30,7 @@ type WebServicesTestSuite struct {
}
func (s *WebServicesTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "mobile/web_services")
tests.RemoveAllMobileWebServices(s.T())
}
func (s *WebServicesTestSuite) TestCreateWebService() {
@ -44,7 +45,7 @@ func (s *WebServicesTestSuite) TestCreateWebService() {
`)
var webService *webServiceResponse
tests.DoSuccessPost(s.T(), "mobile/web_services", payload, &webService)
tests.DoSuccessPostAdmin(s.T(), "mobile/web_services", payload, &webService)
assert.Equal(s.T(), "facebook", webService.Name)
assert.Equal(s.T(), "desc", webService.Description)
@ -64,9 +65,9 @@ func (s *WebServicesTestSuite) TestCreateWebServiceWithAlreadyExistingName() {
}
`)
tests.DoSuccessPost(s.T(), "mobile/web_services", payload, nil)
tests.DoSuccessPostAdmin(s.T(), "mobile/web_services", payload, nil)
response := tests.DoPost("mobile/web_services", payload, nil)
response := tests.DoPostAdmin(s.T(), "mobile/web_services", payload, nil)
assert.Equal(s.T(), 409, response.StatusCode)
}
@ -81,7 +82,7 @@ func (s *WebServicesTestSuite) TestCreateWebServiceWithMatchRules() {
`)
var webService *webServiceResponse
tests.DoSuccessPost(s.T(), "mobile/web_services", payload, &webService)
tests.DoSuccessPostAdmin(s.T(), "mobile/web_services", payload, &webService)
assert.Equal(s.T(), []*command.MatchRule{{
Field: "label",
@ -102,7 +103,7 @@ func (s *WebServicesTestSuite) TestUpdateWebService() {
}
`)
var webService *webServiceResponse
tests.DoSuccessPost(s.T(), "mobile/web_services", payload, &webService)
tests.DoSuccessPostAdmin(s.T(), "mobile/web_services", payload, &webService)
updatePayload := []byte(`{
"name":"meta",
@ -113,7 +114,7 @@ func (s *WebServicesTestSuite) TestUpdateWebService() {
`)
var updatedWebService *webServiceResponse
tests.DoSuccessPut(s.T(), "mobile/web_services/"+webService.Id, updatePayload, &updatedWebService)
tests.DoSuccessPutAdmin(s.T(), "mobile/web_services/"+webService.Id, updatePayload, &updatedWebService)
assert.Equal(s.T(), "meta", updatedWebService.Name)
assert.Equal(s.T(), []string{"meta", "facebook"}, updatedWebService.Issuers)
@ -131,7 +132,7 @@ func (s *WebServicesTestSuite) TestUpdateWebServiceMatchRule() {
}
`)
var webService *webServiceResponse
tests.DoSuccessPost(s.T(), "mobile/web_services", payload, &webService)
tests.DoSuccessPostAdmin(s.T(), "mobile/web_services", payload, &webService)
updatePayload := []byte(`{
"name":"meta",
@ -142,7 +143,7 @@ func (s *WebServicesTestSuite) TestUpdateWebServiceMatchRule() {
`)
var updatedWebService *webServiceResponse
tests.DoSuccessPut(s.T(), "mobile/web_services/"+webService.Id, updatePayload, &updatedWebService)
tests.DoSuccessPutAdmin(s.T(), "mobile/web_services/"+webService.Id, updatePayload, &updatedWebService)
assert.Equal(s.T(), "issuer", updatedWebService.MatchRules[0].Field)
assert.Equal(s.T(), "facebook.pl", updatedWebService.MatchRules[0].Text)
@ -161,9 +162,9 @@ func (s *WebServicesTestSuite) TestDeleteWebService() {
}
`)
var webService *webServiceResponse
tests.DoSuccessPost(s.T(), "mobile/web_services", payload, &webService)
tests.DoSuccessPostAdmin(s.T(), "mobile/web_services", payload, &webService)
tests.DoSuccessDelete(s.T(), "mobile/web_services/"+webService.Id)
tests.DoSuccessDeleteAdmin(s.T(), "mobile/web_services/"+webService.Id)
response := tests.DoGet("mobile/web_services/"+webService.Id, nil)
assert.Equal(s.T(), 404, response.StatusCode)
@ -179,7 +180,7 @@ func (s *WebServicesTestSuite) TestFindAllWebServices() {
"icons_collections":["123e4567-e89b-12d3-a456-426614174000"]
}
`)
tests.DoSuccessPost(s.T(), "mobile/web_services", payload, nil)
tests.DoSuccessPostAdmin(s.T(), "mobile/web_services", payload, nil)
payload2 := []byte(`
{
@ -190,7 +191,7 @@ func (s *WebServicesTestSuite) TestFindAllWebServices() {
"icons_collections":["123e4567-e89b-12d3-a456-426614174000"]
}
`)
tests.DoSuccessPost(s.T(), "mobile/web_services", payload2, nil)
tests.DoSuccessPostAdmin(s.T(), "mobile/web_services", payload2, nil)
var webServices []*webServiceResponse
tests.DoSuccessGet(s.T(), "mobile/web_services", &webServices)
@ -208,7 +209,7 @@ func (s *WebServicesTestSuite) TestFindWebService() {
}
`)
var createdWebService *webServiceResponse
tests.DoSuccessPost(s.T(), "mobile/web_services", payload, &createdWebService)
tests.DoSuccessPostAdmin(s.T(), "mobile/web_services", payload, &createdWebService)
var webService *webServiceResponse
tests.DoSuccessGet(s.T(), "mobile/web_services/"+createdWebService.Id, &webService)

View File

@ -1,10 +1,11 @@
package tests
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/tests"
"testing"
)
func TestMobileDeviceExtensionIntegrationTestSuite(t *testing.T) {
@ -16,9 +17,9 @@ type MobileDeviceExtensionIntegrationTestSuite struct {
}
func (s *MobileDeviceExtensionIntegrationTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "browser_extensions")
tests.DoSuccessDelete(s.T(), "mobile/devices")
tests.DoSuccessDelete(s.T(), "browser_extensions/devices")
tests.RemoveAllMobileDevices(s.T())
tests.RemoveAllBrowserExtensions(s.T())
tests.RemoveAllBrowserExtensionsDevices(s.T())
}
func (s *MobileDeviceExtensionIntegrationTestSuite) TestGetPending2FaRequests() {

View File

@ -2,11 +2,12 @@ package tests
import (
"fmt"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/tests"
"testing"
)
func TestMobileDeviceExtensionTestSuite(t *testing.T) {
@ -18,9 +19,9 @@ type MobileDeviceExtensionTestSuite struct {
}
func (s *MobileDeviceExtensionTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "browser_extensions")
tests.DoSuccessDelete(s.T(), "mobile/devices")
tests.DoSuccessDelete(s.T(), "browser_extensions/devices")
tests.RemoveAllMobileDevices(s.T())
tests.RemoveAllBrowserExtensions(s.T())
tests.RemoveAllBrowserExtensionsDevices(s.T())
}
func (s *MobileDeviceExtensionTestSuite) TestDoNotFindExtensionsForNotExistingDevice() {

View File

@ -2,11 +2,12 @@ package tests
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/tests"
"net/http"
"testing"
)
func TestMobileDeviceTestSuite(t *testing.T) {
@ -18,7 +19,7 @@ type MobileDeviceTestSuite struct {
}
func (s *MobileDeviceTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "mobile/devices")
tests.RemoveAllMobileDevices(s.T())
}
func (s *MobileDeviceTestSuite) TestCreateMobileDevice() {

View File

@ -1,12 +1,13 @@
package tests
import (
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
query "github.com/twofas/2fas-server/internal/api/mobile/app/queries"
"github.com/twofas/2fas-server/tests"
"testing"
)
func TestMobileNotificationsTestSuite(t *testing.T) {
@ -18,7 +19,7 @@ type MobileNotificationsTestSuite struct {
}
func (s *MobileNotificationsTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "mobile/notifications")
tests.RemoveAllMobileNotifications(s.T())
}
func (s *MobileNotificationsTestSuite) TestCreateMobileNotification() {
@ -26,7 +27,7 @@ func (s *MobileNotificationsTestSuite) TestCreateMobileNotification() {
var notification *query.MobileNotificationPresenter
tests.DoSuccessPost(s.T(), "mobile/notifications", payload, &notification)
tests.DoSuccessPostAdmin(s.T(), "mobile/notifications", payload, &notification)
assert.Equal(s.T(), "android", notification.Platform)
assert.Equal(s.T(), "0.1", notification.Version)
@ -38,11 +39,11 @@ func (s *MobileNotificationsTestSuite) TestCreateMobileNotification() {
func (s *MobileNotificationsTestSuite) TestUpdateMobileNotification() {
payload := []byte(`{"icon":"features","platform":"android","link":"2fas.com","message":"demo","version":"0.1"}`)
var notification *query.MobileNotificationPresenter
tests.DoSuccessPost(s.T(), "mobile/notifications", payload, &notification)
tests.DoSuccessPostAdmin(s.T(), "mobile/notifications", payload, &notification)
payload = []byte(`{"icon":"youtube","platform":"ios","link":"new-2fas.com","message":"new-demo","version":"1.1"}`)
var updatedNotification *query.MobileNotificationPresenter
tests.DoSuccessPut(s.T(), "mobile/notifications/"+notification.Id, payload, &updatedNotification)
tests.DoSuccessPutAdmin(s.T(), "mobile/notifications/"+notification.Id, payload, &updatedNotification)
assert.Equal(s.T(), "ios", updatedNotification.Platform)
assert.Equal(s.T(), "1.1", updatedNotification.Version)
@ -54,9 +55,9 @@ func (s *MobileNotificationsTestSuite) TestUpdateMobileNotification() {
func (s *MobileNotificationsTestSuite) TestDeleteMobileNotification() {
payload := []byte(`{"icon":"features","platform":"android","link":"2fas.com","message":"demo","version":"0.1"}`)
var notification *query.MobileNotificationPresenter
tests.DoSuccessPost(s.T(), "mobile/notifications", payload, &notification)
tests.DoSuccessPostAdmin(s.T(), "mobile/notifications", payload, &notification)
tests.DoSuccessDelete(s.T(), "mobile/notifications/"+notification.Id)
tests.DoSuccessDeleteAdmin(s.T(), "mobile/notifications/"+notification.Id)
response := tests.DoGet("mobile/notifications/"+notification.Id, nil)
assert.Equal(s.T(), 404, response.StatusCode)
@ -73,11 +74,11 @@ func (s *MobileNotificationsTestSuite) TestDeleteNotExistingMobileNotification()
func (s *MobileNotificationsTestSuite) TestFindAllNotifications() {
payload1 := []byte(`{"icon":"features","platform":"android","link":"2fas.com","message":"demo","version":"0.1"}`)
var notification1 *query.MobileNotificationPresenter
tests.DoSuccessPost(s.T(), "mobile/notifications", payload1, &notification1)
tests.DoSuccessPostAdmin(s.T(), "mobile/notifications", payload1, &notification1)
payload2 := []byte(`{"icon":"youtube","platform":"android","link":"2fas.com","message":"demo2","version":"1.1"}`)
var notification2 *query.MobileNotificationPresenter
tests.DoSuccessPost(s.T(), "mobile/notifications", payload2, &notification2)
tests.DoSuccessPostAdmin(s.T(), "mobile/notifications", payload2, &notification2)
var collection []*query.MobileNotificationPresenter
tests.DoSuccessGet(s.T(), "mobile/notifications", &collection)
@ -96,10 +97,10 @@ func (s *MobileNotificationsTestSuite) TestDoNotFindNotifications() {
func (s *MobileNotificationsTestSuite) TestPublishNotification() {
payload := []byte(`{"icon":"features","platform":"android","link":"2fas.com","message":"demo","version":"0.1"}`)
var notification *query.MobileNotificationPresenter
tests.DoSuccessPost(s.T(), "mobile/notifications", payload, &notification)
tests.DoSuccessPostAdmin(s.T(), "mobile/notifications", payload, &notification)
var publishedNotification *query.MobileNotificationPresenter
tests.DoSuccessPost(s.T(), "mobile/notifications/"+notification.Id+"/commands/publish", payload, &publishedNotification)
tests.DoSuccessPostAdmin(s.T(), "mobile/notifications/"+notification.Id+"/commands/publish", payload, &publishedNotification)
assert.NotEmpty(s.T(), "published_at", notification.PublishedAt)
}

View File

@ -2,17 +2,18 @@ package tests
import (
"bytes"
"io/ioutil"
"mime/multipart"
"net/http"
"strings"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
query "github.com/twofas/2fas-server/internal/api/support/app/queries"
"github.com/twofas/2fas-server/tests"
"io/ioutil"
"mime/multipart"
"net/http"
"strings"
"testing"
)
func TestDebugLogsAuditTestSuite(t *testing.T) {
@ -24,7 +25,7 @@ type DebugLogsAuditTestSuite struct {
}
func (s *DebugLogsAuditTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "mobile/support/debug_logs/audit")
tests.DoSuccessDeleteAdmin(s.T(), "mobile/support/debug_logs/audit")
}
func (s *DebugLogsAuditTestSuite) TestCreateDebugLogsAuditClaim() {
@ -32,7 +33,7 @@ func (s *DebugLogsAuditTestSuite) TestCreateDebugLogsAuditClaim() {
auditClaim := new(query.DebugLogsAuditPresenter)
tests.DoSuccessPost(s.T(), "mobile/support/debug_logs/audit/claim", payload, auditClaim)
tests.DoSuccessPostAdmin(s.T(), "mobile/support/debug_logs/audit/claim", payload, auditClaim)
assert.Equal(s.T(), "app-user", auditClaim.Username)
assert.Equal(s.T(), "some description", auditClaim.Description)
@ -43,7 +44,7 @@ func (s *DebugLogsAuditTestSuite) TestUpdateDebugLogsAuditClaim() {
var updatedAuditClaim *query.DebugLogsAuditPresenter
updatePayload := []byte(`{"username": "app-user-1", "description": "another description"}`)
tests.DoSuccessPut(s.T(), "mobile/support/debug_logs/audit/claim/"+auditClaim.Id, updatePayload, &updatedAuditClaim)
tests.DoSuccessPutAdmin(s.T(), "mobile/support/debug_logs/audit/claim/"+auditClaim.Id, updatePayload, &updatedAuditClaim)
assert.Equal(s.T(), "app-user-1", updatedAuditClaim.Username)
assert.Equal(s.T(), "another description", updatedAuditClaim.Description)
@ -120,7 +121,7 @@ func (s *DebugLogsAuditTestSuite) TestGetDebugLogsAudit() {
auditClaim := createDebugLogsAuditClaim(s.T(), "user1", "desc1")
audit := new(query.DebugLogsAuditPresenter)
tests.DoSuccessGet(s.T(), "mobile/support/debug_logs/audit/"+auditClaim.Id, audit)
tests.DoSuccessGetAdmin(s.T(), "mobile/support/debug_logs/audit/"+auditClaim.Id, audit)
assert.Equal(s.T(), auditClaim.Id, audit.Id)
assert.Equal(s.T(), "user1", audit.Username)
@ -130,7 +131,7 @@ func (s *DebugLogsAuditTestSuite) TestGetDebugLogsAudit() {
func (s *DebugLogsAuditTestSuite) TestDeleteDebugLogsAudit() {
auditClaim := createDebugLogsAuditClaim(s.T(), "user1", "desc1")
tests.DoSuccessDelete(s.T(), "mobile/support/debug_logs/audit/"+auditClaim.Id)
tests.DoSuccessDeleteAdmin(s.T(), "mobile/support/debug_logs/audit/"+auditClaim.Id)
response := tests.DoGet("mobile/support/debug_logs/audit/"+auditClaim.Id, nil)
assert.Equal(s.T(), 404, response.StatusCode)
@ -141,7 +142,7 @@ func (s *DebugLogsAuditTestSuite) TestFindAllDebugLogsAudit() {
createDebugLogsAuditClaim(s.T(), "user2", "desc2")
var audits []*query.DebugLogsAuditPresenter
tests.DoSuccessGet(s.T(), "mobile/support/debug_logs/audit", &audits)
tests.DoSuccessGetAdmin(s.T(), "mobile/support/debug_logs/audit", &audits)
assert.Len(s.T(), audits, 2)
}
@ -150,7 +151,7 @@ func createDebugLogsAuditClaim(t *testing.T, username, description string) *quer
payload := []byte(`{"username": "` + username + `", "description": "` + description + `"}`)
auditClaim := new(query.DebugLogsAuditPresenter)
tests.DoSuccessPost(t, "mobile/support/debug_logs/audit/claim", payload, auditClaim)
tests.DoSuccessPostAdmin(t, "mobile/support/debug_logs/audit/claim", payload, auditClaim)
return auditClaim
}