Skip to content

Commit 3cfdc8d

Browse files
authored
feat: send server url sha256 encoded to update server (#1311)
1 parent 7cba65e commit 3cfdc8d

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

packages/web-runtime/src/container/bootstrap.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ import {
8080
} from './sse'
8181
import { loadAppTranslations } from '../helpers/language'
8282
import { urlJoin } from '@opencloud-eu/web-client'
83+
import { sha256 } from '@noble/hashes/sha2.js'
84+
import { bytesToHex } from '@noble/hashes/utils.js'
8385

8486
const getEmbedConfigFromQuery = (
8587
doesEmbedEnabledOptionExists: boolean
@@ -705,12 +707,15 @@ export const announceUpdates = async ({
705707
}
706708

707709
try {
710+
const encoder = new TextEncoder()
711+
const sha256ServerUrl = sha256(encoder.encode(configStore.serverUrl))
712+
708713
updatesStore.setIsLoading(true)
709714
const { data }: { data: Updates } = await clientService.httpUnAuthenticated.get(
710715
'https://update.opencloud.eu/server.json',
711716
{
712717
params: {
713-
server: configStore.serverUrl,
718+
server: bytesToHex(sha256ServerUrl),
714719
edition: capabilityStore.status.edition || 'rolling',
715720
version: capabilityStore.status.productversion
716721
}

packages/web-runtime/tests/unit/container/bootstrap.spec.ts

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
import { mock } from 'vitest-mock-extended'
1+
import { mock, mockDeep } from 'vitest-mock-extended'
22
import { createApp, defineComponent, App } from 'vue'
3-
import { useAppsStore, useConfigStore } from '@opencloud-eu/web-pkg'
3+
import {
4+
CapabilityStore,
5+
ClientService,
6+
ConfigStore,
7+
useAppsStore,
8+
useConfigStore,
9+
useUpdatesStore
10+
} from '@opencloud-eu/web-pkg'
411
import {
512
initializeApplications,
613
announceApplicationsReady,
714
announceCustomScripts,
815
announceCustomStyles,
9-
announceConfiguration
16+
announceConfiguration,
17+
announceUpdates
1018
} from '../../../src/container/bootstrap'
1119
import { buildApplication, loadApplication } from '../../../src/container/application'
12-
import { createTestingPinia } from '@opencloud-eu/web-test-helpers'
20+
import { createTestingPinia, mockAxiosResolve } from '@opencloud-eu/web-test-helpers'
1321

1422
vi.mock('../../../src/container/application')
1523

@@ -217,3 +225,46 @@ describe('announceConfiguration', () => {
217225
expect(configStore.options.embed.enabled).toStrictEqual(false)
218226
})
219227
})
228+
229+
describe('announceUpdates', () => {
230+
it('does not contact the update server, if capability is turned off', async () => {
231+
const configStore = mockDeep<ConfigStore>({ serverUrl: 'https://demo.opencloud.eu' })
232+
const capabilityStore = mockDeep<CapabilityStore>({
233+
capabilities: {
234+
core: { 'check-for-updates': false }
235+
},
236+
status: { productversion: '3.5.0', edition: 'rolling' }
237+
})
238+
const updatesStore = useUpdatesStore()
239+
const clientService = mockDeep<ClientService>()
240+
241+
clientService.httpAuthenticated.get.mockResolvedValue(mockAxiosResolve({}))
242+
await announceUpdates({ clientService, updatesStore, configStore, capabilityStore })
243+
expect(clientService.httpUnAuthenticated.get).not.toHaveBeenCalled()
244+
})
245+
246+
it('sends the correct params to the update server', async () => {
247+
const configStore = mockDeep<ConfigStore>({ serverUrl: 'https://demo.opencloud.eu' })
248+
const capabilityStore = mockDeep<CapabilityStore>({
249+
capabilities: {
250+
core: { 'check-for-updates': true }
251+
},
252+
status: { productversion: '3.5.0', edition: 'rolling' }
253+
})
254+
const updatesStore = useUpdatesStore()
255+
const clientService = mockDeep<ClientService>()
256+
257+
clientService.httpAuthenticated.get.mockResolvedValue(mockAxiosResolve({}))
258+
await announceUpdates({ clientService, updatesStore, configStore, capabilityStore })
259+
expect(clientService.httpUnAuthenticated.get).toHaveBeenCalledWith(
260+
'https://update.opencloud.eu/server.json',
261+
{
262+
params: {
263+
edition: 'rolling',
264+
server: 'feb937bb3019600cd682a7fc66d17a37540d9b3060ffa415373f2ad81f9f3b3a',
265+
version: '3.5.0'
266+
}
267+
}
268+
)
269+
})
270+
})

0 commit comments

Comments
 (0)