Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle paths with whitespaces #2123

Merged
merged 24 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8bdc6cb
fix: handle paths with whitespaces
EmiM Nov 28, 2023
e52adea
fix: handle paths with whitespaces
EmiM Nov 28, 2023
a0a0ffb
Merge branch 'develop' into fix/1966
EmiM Nov 28, 2023
335677a
fix: e2e test for invitation link;
EmiM Nov 28, 2023
4c7387a
fix: mock torHashedPassword in tests
vinkabuki Nov 29, 2023
6df0c5a
Merge branch 'develop' into fix/1966
EmiM Dec 1, 2023
2d293da
Merge branch 'develop' into fix/1966
EmiM Dec 4, 2023
f440117
fix: wrap tor path in double quotes to handle spaces in path; spawn t…
EmiM Dec 5, 2023
6a1ed7b
fix: change exec to execFile for killing process on windows
EmiM Dec 5, 2023
5633470
chore: update changelog
EmiM Dec 5, 2023
e7bb7e6
chore: debug e2e tests
EmiM Dec 5, 2023
8340e50
fix: wrap tor arguments in quotation marks if they're path
EmiM Dec 6, 2023
f111fa9
fix: killing hanging tor processes
EmiM Dec 6, 2023
6bed943
test: add logs for debugging purposes
EmiM Dec 6, 2023
468b8e0
Merge branch 'develop' into fix/1966
EmiM Jan 4, 2024
da7a113
Merge branch 'develop' into fix/1966
EmiM Jan 22, 2024
7071be6
Merge branch 'develop' into fix/1966
EmiM Jan 23, 2024
903760e
test: check if spawning tor needs detached mode
EmiM Jan 23, 2024
adf5d3e
Merge branch 'develop' into fix/1966
EmiM Jan 24, 2024
d534932
chore: debug
EmiM Jan 24, 2024
8857f7b
fix: kill tor processes properly; cleanup changelog
EmiM Jan 25, 2024
a4358f7
chore: cleanup
EmiM Jan 25, 2024
11b674b
chore: cleanup
EmiM Jan 25, 2024
f358ae7
fix: killing tor process tests
EmiM Jan 25, 2024
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
2 changes: 1 addition & 1 deletion packages/backend/src/nest/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class AppModule {
res.end()
}
})

console.log('ok')
return { server, io }
},
inject: [EXPRESS_PROVIDER],
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/nest/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const torBinForPlatform = (basePath = '', binName = 'tor'): string => {
return basePath
}
const ext = process.platform === 'win32' ? '.exe' : ''
return path.join(torDirForPlatform(basePath), `${binName}`.concat(ext))
return `"${path.join(torDirForPlatform(basePath), `${binName}`.concat(ext))}"`
}

export const torDirForPlatform = (basePath?: string): string => {
Expand Down
5 changes: 2 additions & 3 deletions packages/backend/src/nest/tor/tor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,8 @@ export class Tor extends EventEmitter implements OnModuleInit {
reject(new Error("Can't spawn tor - no controlPort"))
return
}

this.process = child_process.spawn(
this.torParamsProvider.torPath,
`${this.torParamsProvider.torPath}`,
[
'--SocksPort',
this.socksPort.toString(),
Expand All @@ -222,7 +221,7 @@ export class Tor extends EventEmitter implements OnModuleInit {
this.torPasswordProvider.torHashedPassword,
// ...this.torProcessParams
],
this.torParamsProvider.options
Object.assign(this.torParamsProvider.options, { shell: true })
)

this.process.stdout.on('data', (data: any) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/static.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export const DESKTOP_DEV_DATA_DIR = 'Quietdev'
export const DESKTOP_DATA_DIR = 'Quiet2'

export enum Site {
DOMAIN = 'tryquiet.org',
MAIN_PAGE = 'https://tryquiet.org/',
Expand Down
13 changes: 9 additions & 4 deletions packages/desktop/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import { getPorts, ApplicationPorts, closeHangingBackendProcess } from './backen
import pkijs, { setEngine, CryptoEngine } from 'pkijs'
import { Crypto } from '@peculiar/webcrypto'
import logger from './logger'
import { DATA_DIR, DEV_DATA_DIR } from '../shared/static'
import { fork, ChildProcess } from 'child_process'
import { argvInvitationCode, getFilesData, parseInvitationCodeDeepUrl } from '@quiet/common'
import {
DESKTOP_DATA_DIR,
DESKTOP_DEV_DATA_DIR,
argvInvitationCode,
getFilesData,
parseInvitationCodeDeepUrl,
} from '@quiet/common'
import { updateDesktopFile, processInvitationCode } from './invitation'
const ElectronStore = require('electron-store')
ElectronStore.initRenderer()
Expand All @@ -33,13 +38,13 @@ const webcrypto = new Crypto()

global.crypto = webcrypto

let dataDir = DATA_DIR
let dataDir = DESKTOP_DATA_DIR
let mainWindow: BrowserWindow | null
let splash: BrowserWindow | null
let invitationUrl: string | null

if (isDev || process.env.DATA_DIR) {
dataDir = process.env.DATA_DIR || DEV_DATA_DIR
dataDir = process.env.DATA_DIR || DESKTOP_DEV_DATA_DIR
}

const appDataPath = path.join(app.getPath('appData'), dataDir)
Expand Down
5 changes: 3 additions & 2 deletions packages/desktop/src/renderer/store/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ import { navigationReducer } from './navigation/navigation.slice'

import appHandlers from './handlers/app'

import { DEV_DATA_DIR } from '../../shared/static'
import { Store } from '../sagas/store.types'
import { DESKTOP_DATA_DIR, DESKTOP_DEV_DATA_DIR } from '@quiet/common'

const dataPath =
process.env.APPDATA ||
(process.platform === 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + '/.config')
const appPath = process.env.DATA_DIR || (process.env.NODE_ENV === 'development' ? DEV_DATA_DIR : 'Quiet')
const appPath =
process.env.DATA_DIR || (process.env.NODE_ENV === 'development' ? DESKTOP_DEV_DATA_DIR : DESKTOP_DATA_DIR)

const options = {
projectName: 'quiet',
Expand Down
3 changes: 0 additions & 3 deletions packages/desktop/src/shared/static.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import mirrorKey from 'keymirror'

export const DEV_DATA_DIR = 'Quietdev'
export const DATA_DIR = 'Quiet2'

export const actionTypes = mirrorKey({
SET_APP_VERSION: undefined,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export class DebugModeModal {
const log = await this.driver.executeScript('arguments[0].click();', button)
console.log('executeScript', log)
} catch (e) {
console.log('Probably click properly close modal')
console.log('Probably clicked hidden close button on debug modal', e)
}
await new Promise<void>(resolve => setTimeout(() => resolve(), 2000))
}
Expand Down
9 changes: 5 additions & 4 deletions packages/e2e-tests/src/tests/invitationLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import {
CreateCommunityModal,
DebugModeModal,
JoinCommunityModal,
JoiningLoadingPanel,
RegisterUsernameModal,
App,
Sidebar,
WarningModal,
} from '../selectors'
import { capitalizeFirstLetter, composeInvitationDeepUrl, parseInvitationCode, userJoinedMessage } from '@quiet/common'
import { composeInvitationDeepUrl, parseInvitationCode, userJoinedMessage } from '@quiet/common'
import { execSync } from 'child_process'
import { type SupportedPlatformDesktop } from '@quiet/types'

Expand All @@ -26,7 +25,7 @@ describe('New user joins using invitation link while having app opened', () => {

beforeAll(async () => {
ownerApp = new App()
guestApp = new App({ useDataDir: false })
guestApp = new App({ defaultDataDir: true })
})

beforeEach(async () => {
Expand Down Expand Up @@ -141,7 +140,9 @@ describe('New user joins using invitation link while having app opened', () => {
const copiedCode = url.hash.substring(1)
expect(() => parseInvitationCode(copiedCode)).not.toThrow()
const data = parseInvitationCode(copiedCode)
execSync(`${command[process.platform as SupportedPlatformDesktop]} "${composeInvitationDeepUrl(data)}"`)
const commandFull = `${command[process.platform as SupportedPlatformDesktop]} "${composeInvitationDeepUrl(data)}"`
console.log(`Calling ${commandFull}`)
execSync(commandFull)
console.log('Guest opened invitation link')
})

Expand Down
17 changes: 11 additions & 6 deletions packages/e2e-tests/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { type SupportedPlatformDesktop } from '@quiet/types'
import getPort from 'get-port'
import path from 'path'
import fs from 'fs'
import { DESKTOP_DATA_DIR } from '@quiet/common'

export interface BuildSetupInit {
port?: number
debugPort?: number
useDataDir?: boolean
defaultDataDir?: boolean
dataDir?: string
fileName?: string
}
Expand All @@ -19,19 +20,20 @@ export class BuildSetup {
public debugPort?: number
public dataDir?: string
private child?: ChildProcessWithoutNullStreams
private useDataDir: boolean
private defaultDataDir: boolean
private fileName?: string

constructor({ port, debugPort, useDataDir = true, dataDir, fileName }: BuildSetupInit) {
constructor({ port, debugPort, defaultDataDir = false, dataDir, fileName }: BuildSetupInit) {
this.port = port
this.debugPort = debugPort
this.useDataDir = useDataDir
this.defaultDataDir = defaultDataDir
this.dataDir = dataDir
this.fileName = fileName
if (fileName) {
this.copyInstallerFile(fileName)
}
if (this.useDataDir && !this.dataDir) {
if (this.defaultDataDir) this.dataDir = DESKTOP_DATA_DIR
if (!this.dataDir) {
this.dataDir = `e2e_${(Math.random() * 10 ** 18).toString(36)}`
}
}
Expand Down Expand Up @@ -100,9 +102,12 @@ export class BuildSetup {
public async createChromeDriver() {
await this.initPorts()
const env = {
DATA_DIR: this.dataDir || 'Quiet',
DEBUG: 'backend*,desktop*,utils*',
DATA_DIR: this.dataDir,
}
// if (this.dataDir) {
// env = Object.assign(env, { DATA_DIR: this.dataDir })
// }
if (process.platform === 'win32') {
console.log('!WINDOWS!')
this.child = spawn(`cd node_modules/.bin & chromedriver.cmd --port=${this.port} --verbose`, [], {
Expand Down
Loading