2024-04-05 11:31:40 +02:00
|
|
|
package pass
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSyncHappyFlow(t *testing.T) {
|
|
|
|
resp, err := configureBrowserExtension()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to configure browser extension: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
browserExtensionDone := make(chan struct{})
|
|
|
|
mobileParingDone := make(chan struct{})
|
2024-05-07 14:04:44 +02:00
|
|
|
confirmMobileChannel := make(chan string)
|
2024-04-05 11:31:40 +02:00
|
|
|
|
|
|
|
fcm := uuid.NewString()
|
2024-04-18 09:02:32 +02:00
|
|
|
deviceID := getDeviceID()
|
2024-04-05 11:31:40 +02:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer close(browserExtensionDone)
|
|
|
|
_, syncToken, err := browserExtensionWaitForConfirm(resp.BrowserExtensionPairingToken)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error when Browser Extension waited for pairing confirm: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-07 14:04:44 +02:00
|
|
|
requestSyncResp, err := browserExtensionRequestSync(syncToken)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error when Browser Extension requested sync confirm: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-05 07:32:34 +02:00
|
|
|
pushResp, err := browserExtensionPush(requestSyncResp.BrowserExtensionWaitToken, map[string]string{"hello": "world!"})
|
2024-05-27 16:56:05 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error when Browser Extension tried to send push notification: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.Logf("Push response: %v", pushResp)
|
|
|
|
|
2024-05-07 14:04:44 +02:00
|
|
|
confirmMobileChannel <- requestSyncResp.MobileConfirmToken
|
|
|
|
|
|
|
|
proxyToken, err := browserExtensionWaitForSyncConfirm(requestSyncResp.BrowserExtensionWaitToken)
|
2024-04-05 11:31:40 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error when Browser Extension waited for sync confirm: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = proxyWebSocket(
|
|
|
|
getWsURL()+"/browser_extension/sync/proxy",
|
|
|
|
proxyToken,
|
|
|
|
"sent from browser extension",
|
|
|
|
"sent from mobile")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Browser Extension: proxy failed: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
defer close(mobileParingDone)
|
|
|
|
|
2024-04-18 09:02:32 +02:00
|
|
|
_, err := confirmMobile(resp.ConnectionToken, deviceID, fcm)
|
2024-04-05 11:31:40 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Mobile: confirm failed: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-07 14:04:44 +02:00
|
|
|
confirmToken := <-confirmMobileChannel
|
2024-04-05 11:31:40 +02:00
|
|
|
|
|
|
|
proxyToken, err := confirmSyncMobile(confirmToken)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Failed to confirm mobile: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if proxyToken == "" {
|
|
|
|
t.Errorf("Mobile: proxy token is empty")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = proxyWebSocket(
|
|
|
|
getWsURL()+"/mobile/sync/proxy",
|
|
|
|
proxyToken,
|
|
|
|
"sent from mobile",
|
|
|
|
"sent from browser extension",
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Mobile: proxy failed: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
<-browserExtensionDone
|
|
|
|
<-mobileParingDone
|
|
|
|
}
|