Skip to content

Commit

Permalink
bug/64863-check-received-error (#2911)
Browse files Browse the repository at this point in the history
* Listen for keyup rather than keydown

Prevent pupils from creating keypress events unnecessarily

* Add fflate for payload compression

* Patch dep upgrades

* Add gzip compression/decompression function
Add tracing

* update assets version

* Remove unused imports

* Add payload size limit to pupil-api submit endpoint

* update assets version

* Add fflate to tslib for function payload decompression

* add fflate to pupil-api

* Add v4 for SubmittedCheckVersion

* Mod sync-results-init
Remove automatic json parsing of the archive to bring it in line with the other decompressor versions.

* Update assets version

* Update util-submit-check to V4

* Add tests

* Sort ascending

* Fix tech-support

* fix lint and tests

* bump deps

* Tooling whitespace battle

* test updates

---------

Co-authored-by: Mohsen Qureshi <[email protected]>
Co-authored-by: Mohsen Qureshi <[email protected]>
  • Loading branch information
3 people authored Oct 2, 2024
1 parent ca98009 commit aaf5a72
Show file tree
Hide file tree
Showing 64 changed files with 1,497 additions and 1,703 deletions.
3 changes: 2 additions & 1 deletion admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"watch:integration": "yarn jest --watch --coverage=no --config ./tests-integration/jest.integration.config.js"
},
"mtc": {
"assets-version": "fa63a2e94a724a41857c2c3c7d3081a4"
"assets-version": "6a569a48061e8e7844eee749fb4527b3"
},
"engines": {
"node": ">= 18"
Expand Down Expand Up @@ -65,6 +65,7 @@
"expressjs-csurf": "https://github.com/DFEAGILEDEVOPS/expressjs-csurf#v2.0.1",
"fast-csv": "^4.1.1",
"feature-toggles": "^1.4.0",
"fflate": "^0.8.2",
"font-awesome": "^4.7.0",
"fs-extra": "^11.1.0",
"govuk-frontend": "^3.2.0",
Expand Down
26 changes: 26 additions & 0 deletions admin/services/compression.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const lzString = require('lz-string')
const fflate = require('fflate')

const moduleToExport = {
/**
Expand Down Expand Up @@ -37,6 +38,31 @@ const moduleToExport = {
*/
decompressFromBase64: function decompress (string) {
return lzString.decompressFromBase64(string)
},

/**
*
* @param data stringified object to compress
* @returns base64 encoded string after gzip compression
*/
compressToGzip: function compressToGzip (data) {
const comp = fflate.gzipSync(fflate.strToU8(data), { level: 8, mem: 8 })
const b64 = btoa(fflate.strFromU8(comp, true))
return b64
},

/**
*
* @param data base64 encoded gzip data
* @returns a stringified object (e.g. the payload)
*/
decompressFromGzip: function decompressFromGzip (b64Data) {
// reverse base64 encoding
const comp = atob(b64Data)
// decompress gzip
const uncompData = fflate.gunzipSync(fflate.strToU8(comp, true))
const uncomp = fflate.strFromU8(uncompData)
return uncomp
}
}

Expand Down
4 changes: 3 additions & 1 deletion admin/services/payload.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ const payloadService = {
let payloadString = ''
if (entity.checkVersion !== undefined && entity.checkVersion === 3) {
payloadString = compressionService.decompressFromBase64(archive)
} else {
} else if (entity.checkVersion === 2) {
payloadString = compressionService.decompressFromUTF16(archive)
} else if (entity.checkVersion === 4) {
payloadString = compressionService.decompressFromGzip(archive)
}
const payload = JSON.parse(payloadString)
payload.checkVersion = entity.checkVersion
Expand Down
5 changes: 3 additions & 2 deletions admin/spec/back-end/service/payload.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ describe('payload.service', () => {
inputs: [],
audit: []
}
jest.spyOn(compressionService, 'decompressFromUTF16').mockReturnValueOnce(JSON.stringify(mockArchive))
jest.spyOn(compressionService, 'decompressFromGzip').mockReturnValueOnce(JSON.stringify(mockArchive))
jest.spyOn(payloadDataService, 'sqlFindOneByCheckCode').mockResolvedValue({
inputs: [],
audit: [],
archive: 'mocked'
archive: 'mocked',
checkVersion: 4
})
await service.getPayload(mockCheckCode)
expect(service.addRelativeTimings).toHaveBeenCalled()
Expand Down
Loading

0 comments on commit aaf5a72

Please sign in to comment.