Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
with:
go-version: '1.22'

- name: Run linters
run: go tool golangci-lint run
Comment thread
krzysztofdrys marked this conversation as resolved.

- name: Unit Test
run: make unit-tests-ci

Expand Down
100 changes: 50 additions & 50 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,59 @@ linters:
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- fatcontext
- forbidigo
- forcetypeassert
- funlen
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoinits
- gochecksumtype
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosmopolitan
- govet
- grouper
- importas
- inamedparam
- ineffassign
- interfacebloat
- lll
- loggercheck
- maintidx
- makezero
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- noctx
- nolintlint
- nonamedreturns
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- protogetter
- reassign
- revive
# - errorlint
# - exhaustive
# - fatcontext
# - forbidigo
# - forcetypeassert
# - funlen
# - ginkgolinter
# - gocheckcompilerdirectives
# - gochecknoinits
# - gochecksumtype
# - gocognit
# - goconst
# - gocritic
# - gocyclo
# - godot
# - gomoddirectives
# - gomodguard
# - goprintffuncname
# - gosec
# - gosmopolitan
# - govet
# - grouper
# - importas
# - inamedparam
# - ineffassign
# - interfacebloat
# - lll
# - loggercheck
# - maintidx
# - makezero
# - mirror
# - misspell
# - musttag
# - nakedret
# - nestif
# - nilerr
# - nilnil
# - noctx
# - nolintlint
# - nonamedreturns
# - nosprintfhostport
# - prealloc
# - predeclared
# - promlinter
# - protogetter
# - reassign
# - revive
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- tagliatelle
# - staticcheck
# - tagliatelle
- testableexamples
- testifylint
- thelper
Expand All @@ -82,7 +82,7 @@ linters:
- usestdlibvars
- wastedassign
- whitespace
- wrapcheck
# - wrapcheck
- zerologlint
settings:
errcheck:
Expand Down
21 changes: 10 additions & 11 deletions e2e-tests/browser_extension/browser_extension_2fa_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"testing"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/e2e-tests"

e2e_tests "github.com/twofas/2fas-server/e2e-tests"
)

func TestBrowserExtensionTwoFactorAuthTestSuite(t *testing.T) {
Expand All @@ -30,12 +30,12 @@ func (s *BrowserExtensionTwoFactorAuthTestSuite) TestRequest2FaToken() {
request2FaTokenPayload := []byte(`{"domain":"https://facebook.com/path/nested"}`)
e2e_tests.DoAPISuccessPost(s.T(), "browser_extensions/"+browserExtension.Id+"/commands/request_2fa_token", request2FaTokenPayload, &tokenRequest)

assert.Equal(s.T(), browserExtension.Id, tokenRequest.ExtensionId)
s.Equal(browserExtension.Id, tokenRequest.ExtensionId)

var tokenRequestById *e2e_tests.AuthTokenRequestResponse
e2e_tests.DoAPISuccessGet(s.T(), "browser_extensions/"+browserExtension.Id+"/2fa_requests/"+tokenRequest.Id, &tokenRequestById)
assert.Equal(s.T(), tokenRequest.Id, tokenRequestById.Id)
assert.Equal(s.T(), "https://facebook.com", tokenRequestById.Domain)
s.Equal(tokenRequest.Id, tokenRequestById.Id)
s.Equal("https://facebook.com", tokenRequestById.Domain)
}

func (s *BrowserExtensionTwoFactorAuthTestSuite) TestFindAll2FaRequestsForBrowserExtension() {
Expand All @@ -50,7 +50,7 @@ func (s *BrowserExtensionTwoFactorAuthTestSuite) TestFindAll2FaRequestsForBrowse
var tokenRequestsCollection []*e2e_tests.AuthTokenRequestResponse
e2e_tests.DoAPISuccessGet(s.T(), "browser_extensions/"+browserExtension.Id+"/2fa_requests", &tokenRequestsCollection)

assert.Len(s.T(), tokenRequestsCollection, 2)
s.Len(tokenRequestsCollection, 2)
}

func (s *BrowserExtensionTwoFactorAuthTestSuite) TestClose2FaTokenRequest() {
Expand All @@ -63,7 +63,7 @@ func (s *BrowserExtensionTwoFactorAuthTestSuite) TestClose2FaTokenRequest() {

var closedTokenRequest *e2e_tests.AuthTokenRequestResponse
e2e_tests.DoAPISuccessGet(s.T(), "browser_extensions/"+browserExtension.Id+"/2fa_requests/"+tokenRequest.Id, &closedTokenRequest)
assert.Equal(s.T(), "completed", closedTokenRequest.Status)
s.Equal("completed", closedTokenRequest.Status)
}

func (s *BrowserExtensionTwoFactorAuthTestSuite) TestCloseNotExisting2FaTokenRequest() {
Expand All @@ -72,7 +72,6 @@ func (s *BrowserExtensionTwoFactorAuthTestSuite) TestCloseNotExisting2FaTokenReq

closeTokenRequestPayload := []byte(`{"status":"completed"}`)
e2e_tests.DoAPIPostAndAssertCode(s.T(), 404, "browser_extensions/"+browserExtension.Id+"/2fa_requests/"+notExistingTokenRequestId.String()+"/commands/close_2fa_request", closeTokenRequestPayload, nil)

}

func (s *BrowserExtensionTwoFactorAuthTestSuite) TestDoNotReturnClosed2FaRequests() {
Expand All @@ -86,7 +85,7 @@ func (s *BrowserExtensionTwoFactorAuthTestSuite) TestDoNotReturnClosed2FaRequest

var response []*e2e_tests.AuthTokenRequestResponse
e2e_tests.DoAPISuccessGet(s.T(), "browser_extensions/"+browserExtension.Id+"/2fa_requests", &response)
assert.Len(s.T(), response, 0)
s.Empty(response)
}

func (s *BrowserExtensionTwoFactorAuthTestSuite) TestTerminate2FaRequest() {
Expand All @@ -100,7 +99,7 @@ func (s *BrowserExtensionTwoFactorAuthTestSuite) TestTerminate2FaRequest() {

var response *e2e_tests.AuthTokenRequestResponse
e2e_tests.DoAPISuccessGet(s.T(), "browser_extensions/"+browserExtension.Id+"/2fa_requests/"+tokenRequest.Id, &response)
assert.Equal(s.T(), "terminated", response.Status)
s.Equal("terminated", response.Status)
}

func (s *BrowserExtensionTwoFactorAuthTestSuite) TestClose2FaRequest() {
Expand All @@ -117,5 +116,5 @@ func (s *BrowserExtensionTwoFactorAuthTestSuite) TestClose2FaRequest() {

var closedTokenRequest *e2e_tests.AuthTokenRequestResponse
e2e_tests.DoAPISuccessGet(s.T(), "browser_extensions/"+browserExtension.Id+"/2fa_requests/"+tokenRequest.Id, &closedTokenRequest)
assert.Equal(s.T(), "completed", closedTokenRequest.Status)
s.Equal("completed", closedTokenRequest.Status)
}
27 changes: 20 additions & 7 deletions e2e-tests/browser_extension/browser_extension_2fa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/e2e-tests"

e2e_tests "github.com/twofas/2fas-server/e2e-tests"
)

func TestTwoFactorAuthTestSuite(t *testing.T) {
Expand Down Expand Up @@ -35,7 +36,7 @@ func (s *TwoFactorAuthTestSuite) TestBrowserExtensionAuthFullFlow() {

assertDeviceHasPairedExtension(s.T(), device, browserExtension)
assertBrowserExtensionHasPairedDevice(s.T(), browserExtension, device)
expectedPairingSuccessWebsocket := createPairingSuccessWebsocketMessage(browserExtension, device, devicePubKey)
expectedPairingSuccessWebsocket := createPairingSuccessWebsocketMessage(s.T(), browserExtension, device, devicePubKey)
websocketTestListener.AssertMessageHasBeenReceived(s.T(), expectedPairingSuccessWebsocket)

tokenRequest := e2e_tests.Request2FaToken(s.T(), "facebook.com", browserExtension.Id)
Expand All @@ -46,11 +47,13 @@ func (s *TwoFactorAuthTestSuite) TestBrowserExtensionAuthFullFlow() {

e2e_tests.Send2FaTokenToExtension(s.T(), browserExtension.Id, device.Id, tokenRequest.Id, "2fa-token")

expected2FaTokenWebsocket := createBrowserExtensionReceived2FaTokenMessage(browserExtension.Id, device.Id, tokenRequest.Id)
expected2FaTokenWebsocket := createBrowserExtensionReceived2FaTokenMessage(s.T(), browserExtension.Id, device.Id, tokenRequest.Id)
extensionTokenRequestWebsocketListener.AssertMessageHasBeenReceived(s.T(), expected2FaTokenWebsocket)
}

func createBrowserExtensionReceived2FaTokenMessage(extensionId, deviceId, requestId string) string {
func createBrowserExtensionReceived2FaTokenMessage(t *testing.T, extensionId, deviceId, requestId string) string {
t.Helper()

expected2FaTokenWebsocketMessageRaw := struct {
Event string `json:"event"`
ExtensionId string `json:"extension_id"`
Expand All @@ -65,12 +68,17 @@ func createBrowserExtensionReceived2FaTokenMessage(extensionId, deviceId, reques
Token: "2fa-token",
}

message, _ := json.Marshal(expected2FaTokenWebsocketMessageRaw)
message, err := json.Marshal(expected2FaTokenWebsocketMessageRaw)
if err != nil {
t.Fatalf("failed to marshal expected 2FA token websocket message: %v", err)
}

return string(message)
}

func createPairingSuccessWebsocketMessage(browserExtension *e2e_tests.BrowserExtensionResponse, device *e2e_tests.DeviceResponse, devicePubKey string) string {
func createPairingSuccessWebsocketMessage(t *testing.T, browserExtension *e2e_tests.BrowserExtensionResponse, device *e2e_tests.DeviceResponse, devicePubKey string) string {
t.Helper()

expectedPairingWebsocketMessageRaw := &struct {
Event string `json:"event"`
BrowserExtensionId string `json:"browser_extension_id"`
Expand All @@ -83,12 +91,16 @@ func createPairingSuccessWebsocketMessage(browserExtension *e2e_tests.BrowserExt
DevicePublicKey: devicePubKey,
}

message, _ := json.Marshal(expectedPairingWebsocketMessageRaw)
message, err := json.Marshal(expectedPairingWebsocketMessageRaw)
if err != nil {
t.Fatalf("failed to marshal expected pairing websocket message: %v", err)
}

return string(message)
}

func assertBrowserExtensionHasPairedDevice(t *testing.T, browserExtension *e2e_tests.BrowserExtensionResponse, device *e2e_tests.DeviceResponse) {
t.Helper()
var browserExtensionDevices []*e2e_tests.DeviceResponse
e2e_tests.DoAPISuccessGet(t, "browser_extensions/"+browserExtension.Id+"/devices", &browserExtensionDevices)

Expand All @@ -97,6 +109,7 @@ func assertBrowserExtensionHasPairedDevice(t *testing.T, browserExtension *e2e_t
}

func assertDeviceHasPairedExtension(t *testing.T, device *e2e_tests.DeviceResponse, browserExtension *e2e_tests.BrowserExtensionResponse) {
t.Helper()
var deviceBrowserExtensions []*e2e_tests.BrowserExtensionResponse
e2e_tests.DoAPISuccessGet(t, "mobile/devices/"+device.Id+"/browser_extensions", &deviceBrowserExtensions)

Expand Down
12 changes: 9 additions & 3 deletions e2e-tests/browser_extension/browser_extension_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"testing"

"github.com/google/uuid"
"github.com/twofas/2fas-server/e2e-tests"
"github.com/stretchr/testify/require"

e2e_tests "github.com/twofas/2fas-server/e2e-tests"
)

func Test_BrowserExtensionLogging(t *testing.T) {
Expand All @@ -19,7 +21,9 @@ func Test_BrowserExtensionLogging(t *testing.T) {
Message: "test log",
}

payload, _ := json.Marshal(log)
payload, err := json.Marshal(log)
require.NoError(t, err)

e2e_tests.DoAPISuccessPost(t, "/browser_extensions/"+browserExtension.Id+"/commands/store_log", payload, nil)
}

Expand All @@ -34,6 +38,8 @@ func Test_NotExistingBrowserExtensionLogging(t *testing.T) {
Message: "test log",
}

payload, _ := json.Marshal(log)
payload, err := json.Marshal(log)
require.NoError(t, err)

e2e_tests.DoAPISuccessPost(t, "/browser_extensions/"+someId.String()+"/commands/store_log", payload, nil)
}
Loading
Loading