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
10 changes: 9 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.26'

- name: Test if go.mod and go.sum are up to date
run: |
go mod tidy
git diff --exit-code
- name: Check if conformant to go fix
run: |
go fix ./...
git diff --exit-code
- name: Run linters
run: go tool golangci-lint run

Expand Down
2 changes: 1 addition & 1 deletion docker/admin/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.24-alpine as build
FROM golang:1.26-alpine as build

ENV GO111MODULE=on \
CGO_ENABLED=0 \
Expand Down
2 changes: 1 addition & 1 deletion docker/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.24-alpine as build
FROM golang:1.26-alpine as build

ENV GO111MODULE=on \
CGO_ENABLED=0 \
Expand Down
2 changes: 1 addition & 1 deletion docker/websocket/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.24-alpine as build
FROM golang:1.26-alpine as build

ENV GO111MODULE=on \
CGO_ENABLED=0 \
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/browser_extension/browser_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ func createBrowserExtension(t *testing.T, name string) *http.Response {

pubKey := crypto.PublicKeyToBase64(keyPair.PublicKey)

payload := []byte(fmt.Sprintf(
payload := fmt.Appendf(nil,
`{"name":"%s","browser_name":"go-browser","browser_version":"0.1","public_key":"%s"}`,
name,
pubKey))
pubKey)

return e2e_tests.DoAPIRequest(t, "/browser_extensions", http.MethodPost, payload, nil)
}
16 changes: 8 additions & 8 deletions e2e-tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func CreateDevice(t *testing.T, name, fcmToken string) (*DeviceResponse, string)
keyPair := crypto.GenerateKeyPair(2048)
devicePubKey := crypto.PublicKeyToBase64(keyPair.PublicKey)

payload := []byte(fmt.Sprintf(`{"name":"%s","platform":"android","fcm_token":"%s"}`, name, fcmToken))
payload := fmt.Appendf(nil, `{"name":"%s","platform":"android","fcm_token":"%s"}`, name, fcmToken)

device := new(DeviceResponse)

Expand All @@ -30,10 +30,10 @@ func CreateBrowserExtension(t *testing.T, name string) *BrowserExtensionResponse

pubKey := crypto.PublicKeyToBase64(keyPair.PublicKey)

payload := []byte(
fmt.Sprintf(
payload :=
fmt.Appendf(nil,
`{"name":"%s","browser_name":"go-browser","browser_version":"0.1","public_key":"%s"}`,
name, pubKey))
name, pubKey)

browserExt := new(BrowserExtensionResponse)

Expand All @@ -45,9 +45,9 @@ func CreateBrowserExtension(t *testing.T, name string) *BrowserExtensionResponse
func CreateBrowserExtensionWithPublicKey(t *testing.T, name, publicKey string) *BrowserExtensionResponse {
t.Helper()

payload := []byte(
fmt.Sprintf(`{"name":"%s","browser_name":"go-browser","browser_version":"0.1","public_key":"%s"}`,
name, publicKey))
payload :=
fmt.Appendf(nil, `{"name":"%s","browser_name":"go-browser","browser_version":"0.1","public_key":"%s"}`,
name, publicKey)

browserExt := new(BrowserExtensionResponse)

Expand Down Expand Up @@ -100,7 +100,7 @@ func Request2FaToken(t *testing.T, domain, extensionId string) *AuthTokenRequest

var response *AuthTokenRequestResponse

payload := []byte(fmt.Sprintf(`{"domain":"%s"}`, domain))
payload := fmt.Appendf(nil, `{"domain":"%s"}`, domain)

DoAPISuccessPost(t, "browser_extensions/"+extensionId+"/commands/request_2fa_token", payload, &response)

Expand Down
24 changes: 12 additions & 12 deletions e2e-tests/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ func (a *BasicAuth) Header() string {
return "Basic " + base64.StdEncoding.EncodeToString([]byte(base))
}

func DoAPISuccessPost(t *testing.T, uri string, payload []byte, resp interface{}) {
func DoAPISuccessPost(t *testing.T, uri string, payload []byte, resp any) {
t.Helper()
response := doRequest(t, apiRawURL, uri, http.MethodPost, payload, resp)
require.Equal(t, http.StatusOK, response.StatusCode)
}

func DoAdminAPISuccessPost(t *testing.T, uri string, payload []byte, resp interface{}) {
func DoAdminAPISuccessPost(t *testing.T, uri string, payload []byte, resp any) {
t.Helper()
response := doRequest(t, adminRawURL, uri, http.MethodPost, payload, resp)
bb, err := io.ReadAll(response.Body)
Expand All @@ -45,29 +45,29 @@ func DoAdminAPISuccessPost(t *testing.T, uri string, payload []byte, resp interf
require.Equal(t, http.StatusOK, response.StatusCode, "invalid status code, response payload is: %q", string(bb))
}

func DoAdminPostAndAssertCode(t *testing.T, expCode int, uri string, payload []byte, resp interface{}) {
func DoAdminPostAndAssertCode(t *testing.T, expCode int, uri string, payload []byte, resp any) {
t.Helper()
response := doRequest(t, adminRawURL, uri, http.MethodPost, payload, resp)
require.Equal(t, expCode, response.StatusCode)
}

func DoAPIPostAndAssertCode(t *testing.T, expCode int, uri string, payload []byte, resp interface{}) {
func DoAPIPostAndAssertCode(t *testing.T, expCode int, uri string, payload []byte, resp any) {
t.Helper()
response := doRequest(t, apiRawURL, uri, http.MethodPost, payload, resp)
require.Equal(t, expCode, response.StatusCode)
}

func DoAPIRequest(t *testing.T, uri, method string, payload []byte, resp interface{}) *http.Response {
func DoAPIRequest(t *testing.T, uri, method string, payload []byte, resp any) *http.Response {
t.Helper()
return doRequest(t, apiRawURL, uri, method, payload, resp)
}

func DoAdminRequest(t *testing.T, uri, method string, payload []byte, resp interface{}) *http.Response {
func DoAdminRequest(t *testing.T, uri, method string, payload []byte, resp any) *http.Response {
t.Helper()
return doRequest(t, apiRawURL, uri, method, payload, resp)
}

func DoAdminSuccessPut(t *testing.T, uri string, payload []byte, resp interface{}) {
func DoAdminSuccessPut(t *testing.T, uri string, payload []byte, resp any) {
t.Helper()
response := doRequest(t, adminRawURL, uri, http.MethodPut, payload, resp)
bb, err := io.ReadAll(response.Body)
Expand All @@ -76,26 +76,26 @@ func DoAdminSuccessPut(t *testing.T, uri string, payload []byte, resp interface{
require.Equal(t, http.StatusOK, response.StatusCode, "invalid status code, response payload is: %q", string(bb))
}

func DoAPISuccessPut(t *testing.T, uri string, payload []byte, resp interface{}) {
func DoAPISuccessPut(t *testing.T, uri string, payload []byte, resp any) {
t.Helper()

response := doRequest(t, apiRawURL, uri, http.MethodPut, payload, resp)
require.Equal(t, http.StatusOK, response.StatusCode)
}

func DoAPISuccessGet(t *testing.T, uri string, resp interface{}) {
func DoAPISuccessGet(t *testing.T, uri string, resp any) {
t.Helper()

response := doRequest(t, apiRawURL, uri, http.MethodGet, nil /*payload*/, resp)
require.Equal(t, http.StatusOK, response.StatusCode)
}

func DoAPIGet(t *testing.T, uri string, resp interface{}) *http.Response {
func DoAPIGet(t *testing.T, uri string, resp any) *http.Response {
t.Helper()
return doRequest(t, apiRawURL, uri, http.MethodGet, nil /*payload*/, resp)
}

func DoAdminSuccessGet(t *testing.T, uri string, resp interface{}) {
func DoAdminSuccessGet(t *testing.T, uri string, resp any) {
t.Helper()
response := doRequest(t, adminRawURL, uri, http.MethodGet, nil /*payload*/, resp)
require.Equal(t, http.StatusOK, response.StatusCode)
Expand All @@ -113,7 +113,7 @@ func DoAPISuccessDelete(t *testing.T, uri string) {
require.Equal(t, http.StatusOK, response.StatusCode)
}

func doRequest(t *testing.T, base, uri, method string, payload []byte, resp interface{}) *http.Response {
func doRequest(t *testing.T, base, uri, method string, payload []byte, resp any) *http.Response {
t.Helper()
baseURL, err := url.Parse(base)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/icons/icons_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tests
import (
"encoding/base64"
"encoding/json"
"io/ioutil"
"os"
"testing"

"github.com/jaswdr/faker"
Expand Down Expand Up @@ -38,7 +38,7 @@ func (s *IconsRequestsTestSuite) TestCreateIconRequest() {
func (s *IconsRequestsTestSuite) TestCreateIconRequestWithNotAllowedIconDimensions() {
img := faker.New().Image().Image(120, 60)

pngImg, err := ioutil.ReadFile(img.Name())
pngImg, err := os.ReadFile(img.Name())

if err != nil {
s.T().Error(err)
Expand Down Expand Up @@ -157,7 +157,7 @@ func createIconRequest(t *testing.T, serviceName string) *queries.IconRequestPre

img := faker.New().Image().Image(120, 120)

pngImg, err := ioutil.ReadFile(img.Name())
pngImg, err := os.ReadFile(img.Name())

if err != nil {
t.Error(err)
Expand Down
5 changes: 3 additions & 2 deletions e2e-tests/icons/icons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package tests

import (
"encoding/base64"
"io/ioutil"
"os"

"testing"

"github.com/jaswdr/faker"
Expand All @@ -16,7 +17,7 @@ func createIcon(t *testing.T) *query.IconPresenter {
t.Helper()
img := faker.New().Image().Image(120, 120)

pngImg, err := ioutil.ReadFile(img.Name())
pngImg, err := os.ReadFile(img.Name())

if err != nil {
t.Error(err)
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/icons/web_services_dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ func createWebService(t *testing.T) *webServiceResponse {
iconsCollection := createIconsCollection(t)

id := fmt.Sprintf("service-%d", rand.Int()) // nolint:gosec // only for tests
payload := []byte(fmt.Sprintf(`
payload := fmt.Appendf(nil, `
{
"name":"%s",
"description":"another",
"issuers":["facebook", "m.facebook"],
"tags":["shitbook"],
"icons_collections":["%s"]
}
`, id, iconsCollection.Id))
`, id, iconsCollection.Id)

var webService *webServiceResponse

Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/mobile/mobile_device_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func (s *MobileDeviceExtensionTestSuite) TestExtensionHasAlreadyBeenConnected()
device, devicePubKey := e2e_tests.CreateDevice(s.T(), "go-test-device", "some-device-id")
e2e_tests.PairDeviceWithBrowserExtension(s.T(), devicePubKey, extension, device)

payload := []byte(fmt.Sprintf(`{"extension_id":"%s","device_name":"%s","device_public_key":"%s"}`,
payload := fmt.Appendf(nil, `{"extension_id":"%s","device_name":"%s","device_public_key":"%s"}`,
extension.Id,
device.Name,
devicePubKey))
devicePubKey)

e2e_tests.DoAPIPostAndAssertCode(s.T(),
409,
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/mobile/mobile_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ func (s *MobileDeviceTestSuite) TestCreateMobileDevice() {

func createDevice(t *testing.T, name, fcmToken string) *http.Response {
t.Helper()
payload := []byte(fmt.Sprintf(`{"name":"%s","platform":"android","fcm_token":"%s"}`, name, fcmToken))
payload := fmt.Appendf(nil, `{"name":"%s","platform":"android","fcm_token":"%s"}`, name, fcmToken)
return e2e_tests.DoAPIRequest(t, "mobile/devices", http.MethodPost, payload, nil)
}
4 changes: 2 additions & 2 deletions e2e-tests/mobile/mobile_security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Test_MobileApiBandwidthAbuse(t *testing.T) {

eg := errgroup.Group{}
eg.SetLimit(noOfWorkers)
for i := 0; i < noOfRequest; i++ {
for range noOfRequest {
eg.Go(func() error {
resp := e2e_tests.DoAPIGet(t, "/mobile/devices/"+someId.String()+"/browser_extensions", nil)

Expand Down Expand Up @@ -58,7 +58,7 @@ func Test_BrowserExtensionApiBandwidthAbuse(t *testing.T) {

eg := errgroup.Group{}
eg.SetLimit(noOfWorkers)
for i := 0; i < noOfRequest; i++ {
for range noOfRequest {
eg.Go(func() error {
resp := e2e_tests.DoAPIGet(t, "/browser_extensions/"+someId.String(), nil)

Expand Down
5 changes: 2 additions & 3 deletions e2e-tests/support/mobile_debug_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"strings"
Expand Down Expand Up @@ -74,10 +73,10 @@ func (s *DebugLogsAuditTestSuite) TestFulfillDebugLogsAuditClaim() {
s.Require().NoError(err)
s.Equal(200, response.StatusCode)

reqB, _ := ioutil.ReadAll(body)
reqB, _ := io.ReadAll(body)
s.T().Log(string(reqB))

rawBody, _ := ioutil.ReadAll(response.Body)
rawBody, _ := io.ReadAll(response.Body)

s.T().Log(string(rawBody))
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/twofas/2fas-server

go 1.24.0
go 1.26.0

require (
firebase.google.com/go/v4 v4.15.2
Expand Down
2 changes: 1 addition & 1 deletion internal/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewApplication(applicationName string, config config.Configuration) (*Appli
pushClient = push.NewFakePushClient()
} else {
sess, err := session.NewSession(&aws.Config{
Region: aws.String(config.Aws.Region),
Region: new(config.Aws.Region),
})
if err != nil {
return nil, fmt.Errorf("failed to create aws session: %w", err)
Expand Down
10 changes: 5 additions & 5 deletions internal/api/browser_extension/app/command/request_2fa_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (h *Request2FaTokenHandler) Handle(
return nil, err
}

data := map[string]interface{}{
data := map[string]any{
"extension_id": extId.String(),
"request_id": cmd.Id,
"domain": cmd.Domain,
Expand Down Expand Up @@ -113,7 +113,7 @@ func (h *Request2FaTokenHandler) sendPush(
ctx context.Context,
log logging.FieldLogger,
device *domain.ExtensionDevice,
data map[string]interface{}) PushNotificationStatus {
data map[string]any) PushNotificationStatus {
if device.FcmToken == "" {
log.Info("Cannot send push notification, missing FCM token")
return PushNotificationStatusNoFCM
Expand Down Expand Up @@ -157,7 +157,7 @@ func (h *Request2FaTokenHandler) findPairedDevices(

func (h *Request2FaTokenHandler) sendNotification(ctx context.Context,
device *domain.ExtensionDevice,
data map[string]interface{}) error {
data map[string]any) error {
var notification *messaging.Message

switch device.Platform {
Expand All @@ -176,7 +176,7 @@ func (h *Request2FaTokenHandler) sendNotification(ctx context.Context,
)
}

func createPushNotificationForIos(token string, data map[string]interface{}) *messaging.Message {
func createPushNotificationForIos(token string, data map[string]any) *messaging.Message {
ttl := time.Now().Add(tokenPushNotificationTtl)

return &messaging.Message{
Expand All @@ -200,7 +200,7 @@ func createPushNotificationForIos(token string, data map[string]interface{}) *me
}
}

func createPushNotificationForAndroid(token string, data map[string]interface{}) *messaging.Message {
func createPushNotificationForAndroid(token string, data map[string]any) *messaging.Message {
androidData := make(map[string]string, len(data))

for key, value := range data {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/health/ports/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (r *RoutesHandler) RedisInfo(c *gin.Context) {

func (r *RoutesHandler) GetApplicationConfiguration(c *gin.Context) {
sess, err := session.NewSession(&aws.Config{
Region: aws.String(config.Config.Aws.Region),
Region: new(config.Config.Aws.Region),
})
if err != nil {
// This is an internal endpoint, so we can return the error as is.
Expand Down
5 changes: 3 additions & 2 deletions internal/api/support/app/command/create_debug_log_audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package command
import (
"bytes"
"errors"
"io/ioutil"
"io"

"mime/multipart"
"path/filepath"

Expand Down Expand Up @@ -58,7 +59,7 @@ func (h *CreateDebugLogsAuditHandler) Handle(command *CreateDebugLogsAudit) erro
return err
}

file, _ := ioutil.ReadAll(logsFile)
file, _ := io.ReadAll(logsFile)

logsFileReader := bytes.NewReader(file)

Expand Down
Loading
Loading