Skip to content

Commit

Permalink
Update Quiet client to detect a v2 invite link format (#2330)
Browse files Browse the repository at this point in the history
* refactor: adjust customProtocolSaga code to be similar to deepLinkSaga; Move parsing code from main.ts to saga

* feat: handle old (psk, orbitdbIdentity, addresses) and new (cid, token, serverAddress, inviterAddress) invitation link format

* chore: add joinNetwork saga that gathers data for createNetwork; mock DOWNLOAD_INVITE_DATA response

* refactor: invitation link parsers

* refactor: simplify deepLink and customProtocol sagas

* chore: add missing github workflow for running common package tests

* feat: add one script for preparing AppImage for e2e tests on Linux

* chore: remove unused code responsible for locking invitation link form on deep linking
  • Loading branch information
EmiM authored Apr 12, 2024
1 parent c18e97c commit 7cc1d8e
Show file tree
Hide file tree
Showing 53 changed files with 855 additions and 452 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/utils-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Common package tests

on:
pull_request:
paths:
- packages/common/**

jobs:
utils-tests:
timeout-minutes: 25
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-20.04, macos-latest, windows-2019]

steps:
- name: "Print OS"
run: echo ${{ matrix.os }}

- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: "Setup environment"
uses: ./.github/actions/setup-env
with:
bootstrap-packages: "@quiet/eslint-config,@quiet/logger,@quiet/types,@quiet/common"

- name: "Unit tests"
run: lerna run test --scope @quiet/common --stream
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

# New features:

* Add support for new format of invitation link: `c=<cid>&t=<token>&s=<serverAddress>&i=<inviterAddress>` ([#2310](https://github.com/TryQuiet/quiet/issues/2310))

# Refactorings:

# Fixes:
# Fixes

# Chores

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"start:desktop": "lerna run --scope @quiet/desktop start",
"lint:all": "lerna run lint",
"distAndRunE2ETests:mac:local": "lerna run --scope @quiet/desktop distMac:local && lerna run --scope e2e-tests test:localBinary --",
"e2e:linux:build": "lerna run --scope @quiet/backend webpack:prod && lerna run --scope @quiet/desktop distUbuntu && lerna run --scope e2e-tests linux:copy",
"e2e:linux:run": "lerna run --scope e2e-tests test --",
"prepare": "husky",
"lint-staged": "lerna run lint-staged"
},
Expand Down
13 changes: 8 additions & 5 deletions packages/backend/jestSetup.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { setEngine, CryptoEngine } from'pkijs'
import { setEngine, CryptoEngine } from 'pkijs'
import { Crypto } from '@peculiar/webcrypto'

const crypto = new Crypto();
global.crypto = crypto;
const crypto = new Crypto()
global.crypto = crypto

setEngine('newEngine', new CryptoEngine({
setEngine(
'newEngine',
new CryptoEngine({
name: 'newEngine',
// @ts-ignore
crypto: crypto,
}))
})
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { CustomEvent } from '@libp2p/interfaces/events'
import { jest, beforeEach, describe, it, expect, afterEach } from '@jest/globals'
import { communities, getFactory, identity, prepareStore, Store } from '@quiet/state-manager'
import { createPeerId, createTmpDir, libp2pInstanceParams, removeFilesFromDir, tmpQuietDirPath } from '../common/utils'

import { NetworkStats, type Community, type Identity, type InitCommunityPayload } from '@quiet/types'
import { NetworkStats, type Community, type Identity } from '@quiet/types'
import { LazyModuleLoader } from '@nestjs/core'
import { TestingModule, Test } from '@nestjs/testing'
import { FactoryGirl } from 'factory-girl'
Expand Down Expand Up @@ -114,7 +113,6 @@ beforeEach(async () => {
})

afterEach(async () => {
await libp2pService?.libp2pInstance?.stop()
if (connectionsManagerService) {
await connectionsManagerService.closeAllServices()
}
Expand All @@ -123,6 +121,10 @@ afterEach(async () => {

describe('Connections manager', () => {
it('saves peer stats when peer has been disconnected', async () => {
// @ts-expect-error
libp2pService.processInChunksService.init = jest.fn()
// @ts-expect-error
libp2pService.processInChunksService.process = jest.fn()
class RemotePeerEventDetail {
peerId: string

Expand All @@ -138,6 +140,10 @@ describe('Connections manager', () => {

// Peer connected
await connectionsManagerService.init()
await connectionsManagerService.launchCommunity({
community,
network: { peerId: userIdentity.peerId, hiddenService: userIdentity.hiddenService },
})
libp2pService.connectedPeers.set(peerId.toString(), DateTime.utc().valueOf())

// Peer disconnected
Expand All @@ -146,11 +152,16 @@ describe('Connections manager', () => {
remotePeer: new RemotePeerEventDetail(peerId.toString()),
remoteAddr: new RemotePeerEventDetail(remoteAddr),
}
await waitForExpect(async () => {
expect(libp2pService.libp2pInstance).not.toBeUndefined()
}, 2_000)
libp2pService.libp2pInstance?.dispatchEvent(
new CustomEvent('peer:disconnect', { detail: peerDisconectEventDetail })
)
await waitForExpect(async () => {
expect(libp2pService.connectedPeers.size).toEqual(0)
}, 2000)

expect(libp2pService.connectedPeers.size).toEqual(0)
await waitForExpect(async () => {
expect(await localDbService.get(LocalDBKeys.PEERS)).not.toBeNull()
}, 2000)
Expand Down
17 changes: 17 additions & 0 deletions packages/backend/src/nest/socket/socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
type DeleteChannelResponse,
type MessagesLoadedPayload,
type NetworkInfo,
CreateNetworkPayload,
CommunityOwnership,
} from '@quiet/types'
import EventEmitter from 'events'
import { CONFIG_OPTIONS, SERVER_IO_PROVIDER } from '../const'
Expand Down Expand Up @@ -169,6 +171,21 @@ export class SocketService extends EventEmitter implements OnModuleInit {
}
)

socket.on(
SocketActionTypes.DOWNLOAD_INVITE_DATA,
async (payload: { serverAddress: string; cid: string }, callback: (response: CreateNetworkPayload) => void) => {
// this.emit(SocketActionTypes.DOWNLOAD_INVITE_DATA, payload, callback)
console.log('download invite data', payload)
// Mock it for now
callback({
ownership: CommunityOwnership.User,
peers: [],
psk: '',
ownerOrbitDbIdentity: '',
})
}
)

socket.on(SocketActionTypes.LEAVE_COMMUNITY, async () => {
this.logger('Leaving community')
this.emit(SocketActionTypes.LEAVE_COMMUNITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const areObjectsEqual = (obj1: any, obj2: any): boolean => {
// Using this only makes sense for small objects whose properties are in the same order
return JSON.stringify(obj1) === JSON.stringify(obj2)
}
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export * from './libp2p'
export * from './tests'
export * from './auth'
export * from './messages'
export * from './compare'
export * from './dir'
Loading

0 comments on commit 7cc1d8e

Please sign in to comment.