mirror of
https://github.com/twofas/2fas-server.git
synced 2024-12-04 16:20:13 +01:00
fix(pass): make it possible to pair multiple times
This commit is contained in:
parent
9962387abc
commit
2299f46da1
@ -57,12 +57,7 @@ func configureBrowserExtension() (ConfigureBrowserExtensionResponse, error) {
|
||||
}
|
||||
|
||||
// confirmMobile confirms pairing and returns mobile proxy token.
|
||||
func confirmMobile(connectionToken, fcm string) (string, error) {
|
||||
deviceID := uuid.NewString()
|
||||
if deviceIDFromEnv := os.Getenv("TEST_DEVICE_ID"); deviceIDFromEnv != "" {
|
||||
deviceID = deviceIDFromEnv
|
||||
}
|
||||
|
||||
func confirmMobile(connectionToken, deviceID, fcm string) (string, error) {
|
||||
req := struct {
|
||||
DeviceID string `json:"device_id"`
|
||||
FCMToken string `json:"fcm_token"`
|
||||
|
15
tests/pass/lib.go
Normal file
15
tests/pass/lib.go
Normal file
@ -0,0 +1,15 @@
|
||||
package pass
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func getDeviceID() string {
|
||||
deviceID := uuid.NewString()
|
||||
if deviceIDFromEnv := os.Getenv("TEST_DEVICE_ID"); deviceIDFromEnv != "" {
|
||||
deviceID = deviceIDFromEnv
|
||||
}
|
||||
return deviceID
|
||||
}
|
@ -21,7 +21,9 @@ func TestPairHappyFlow(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to configure browser extension: %v", err)
|
||||
}
|
||||
testPairing(t, resp)
|
||||
|
||||
deviceID := getDeviceID()
|
||||
testPairing(t, deviceID, resp)
|
||||
}
|
||||
|
||||
func TestPairMultipleTimes(t *testing.T) {
|
||||
@ -29,14 +31,17 @@ func TestPairMultipleTimes(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to configure browser extension: %v", err)
|
||||
}
|
||||
const messageSize = 1024 * 1024
|
||||
|
||||
deviceID := getDeviceID()
|
||||
for i := 0; i < 10; i++ {
|
||||
testPairing(t, resp)
|
||||
testPairing(t, deviceID, resp)
|
||||
if t.Failed() {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testPairing(t *testing.T, resp ConfigureBrowserExtensionResponse) {
|
||||
func testPairing(t *testing.T, deviceID string, resp ConfigureBrowserExtensionResponse) {
|
||||
t.Helper()
|
||||
|
||||
browserExtensionDone := make(chan struct{})
|
||||
@ -68,7 +73,7 @@ func testPairing(t *testing.T, resp ConfigureBrowserExtensionResponse) {
|
||||
go func() {
|
||||
defer close(mobileDone)
|
||||
|
||||
mobileProxyToken, err := confirmMobile(resp.ConnectionToken, uuid.NewString())
|
||||
mobileProxyToken, err := confirmMobile(resp.ConnectionToken, deviceID, uuid.NewString())
|
||||
if err != nil {
|
||||
t.Errorf("Mobile: confirm failed: %v", err)
|
||||
return
|
||||
|
@ -16,6 +16,7 @@ func TestSyncHappyFlow(t *testing.T) {
|
||||
mobileParingDone := make(chan struct{})
|
||||
|
||||
fcm := uuid.NewString()
|
||||
deviceID := getDeviceID()
|
||||
|
||||
go func() {
|
||||
defer close(browserExtensionDone)
|
||||
@ -44,7 +45,7 @@ func TestSyncHappyFlow(t *testing.T) {
|
||||
go func() {
|
||||
defer close(mobileParingDone)
|
||||
|
||||
_, err := confirmMobile(resp.ConnectionToken, fcm)
|
||||
_, err := confirmMobile(resp.ConnectionToken, deviceID, fcm)
|
||||
if err != nil {
|
||||
t.Errorf("Mobile: confirm failed: %v", err)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user