Skip to content

Commit f31d5f8

Browse files
Test modem firmware filename validation
1 parent ff8421e commit f31d5f8

File tree

2 files changed

+107
-7
lines changed

2 files changed

+107
-7
lines changed

src/components/ModemUpdateDialogView.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ import {
2929
} from '../reducers/modemReducer';
3030
import { WithRequired } from '../util/types';
3131

32+
export const isValidNrf9160FirmwareName = (filename: string | undefined) =>
33+
!filename || /mfw_nrf9160_\d+\.\d+\.\d+.*.zip/.test(filename);
34+
35+
export const isValidNrf91x1FirmwareName = (filename: string | undefined) =>
36+
!filename ||
37+
/mfw_nrf91x1_\d+\.\d+\.\d+.*.zip/.test(filename) ||
38+
/mfw.*nrf91.1_\d+\.\d+\.\d+\.zip/.test(filename);
39+
3240
const ModemUpdateDialogView = () => {
3341
const abortController = useRef(new AbortController());
3442
const [progress, setProgress] =
@@ -61,17 +69,12 @@ const ModemUpdateDialogView = () => {
6169

6270
if (is9160) {
6371
expectedFileName = 'mfw_nrf9160_X.X.X*.zip';
64-
expectedFwName =
65-
!modemFwName || /mfw_nrf9160_\d+\.\d+\.\d+.*.zip/.test(modemFwName);
72+
expectedFwName = isValidNrf9160FirmwareName(modemFwName);
6673
url =
6774
'https://www.nordicsemi.com/Products/Development-hardware/nrf9160-dk/download#infotabs';
6875
} else if (is91x1) {
6976
expectedFileName = 'mfw_nrf91x1_X.X.X*.zip';
70-
expectedFwName =
71-
!modemFwName ||
72-
/mfw_nrf91x1_\d+\.\d+\.\d+.*.zip/.test(modemFwName) ||
73-
// DECT mfw
74-
/mfw.*nrf91.1_\d+\.\d+\.\d+\.zip/.test(modemFwName);
77+
expectedFwName = isValidNrf91x1FirmwareName(modemFwName);
7578
url = 'https://www.nordicsemi.com/Products/nRF9161/Download';
7679
}
7780

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5+
*/
6+
7+
import {
8+
isValidNrf91x1FirmwareName,
9+
isValidNrf9160FirmwareName,
10+
} from '../ModemUpdateDialogView';
11+
12+
describe('Modem firmware filename validation', () => {
13+
describe('nRF9160 firmware names', () => {
14+
it('accepts names from https://www.nordicsemi.com/Products/nRF9160/Download', () => {
15+
expect(isValidNrf9160FirmwareName('mfw_nrf9160_1.1.0.zip')).toBe(
16+
true,
17+
);
18+
expect(isValidNrf9160FirmwareName('mfw_nrf9160_1.3.7.zip')).toBe(
19+
true,
20+
);
21+
});
22+
23+
it('accepts undefined as valid (no file selected)', () => {
24+
expect(isValidNrf9160FirmwareName(undefined)).toBe(true);
25+
});
26+
27+
describe('invalid names', () => {
28+
it('rejects wrong prefix', () => {
29+
expect(isValidNrf9160FirmwareName('fw_nrf9160_1.0.0.zip')).toBe(
30+
false,
31+
);
32+
});
33+
34+
it('rejects non-zip file', () => {
35+
expect(
36+
isValidNrf9160FirmwareName('mfw_nrf9160_1.1.0.tar'),
37+
).toBe(false);
38+
});
39+
40+
it('rejects nRF91x1 firmware names', () => {
41+
expect(
42+
isValidNrf9160FirmwareName('mfw_nrf91x1_2.0.4.zip'),
43+
).toBe(false);
44+
expect(
45+
isValidNrf9160FirmwareName('mfw-pti_nrf91x1_2.3.8.zip'),
46+
).toBe(false);
47+
});
48+
});
49+
});
50+
51+
describe('nRF91x1 firmware names', () => {
52+
it('accepts names from https://www.nordicsemi.com/Products/nRF9161/Download', () => {
53+
expect(isValidNrf91x1FirmwareName('mfw_nrf91x1_2.0.0.zip')).toBe(
54+
true,
55+
);
56+
expect(isValidNrf91x1FirmwareName('mfw_nrf91x1_2.0.4.zip')).toBe(
57+
true,
58+
);
59+
expect(
60+
isValidNrf91x1FirmwareName('mfw-pti_nrf91x1_2.3.1.zip'),
61+
).toBe(true);
62+
expect(
63+
isValidNrf91x1FirmwareName('mfw-pti_nrf91x1_2.3.8.zip'),
64+
).toBe(true);
65+
});
66+
67+
it('DECT names from https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/getting-started-with-nr-phy', () => {
68+
expect(
69+
isValidNrf91x1FirmwareName('mfw-nr+_nrf91x1_1.0.0.zip'),
70+
).toBe(true);
71+
});
72+
73+
it('accepts undefined as valid (no file selected)', () => {
74+
expect(isValidNrf91x1FirmwareName(undefined)).toBe(true);
75+
});
76+
77+
describe('invalid names', () => {
78+
it('rejects wrong prefix', () => {
79+
expect(isValidNrf91x1FirmwareName('fw_nrf91x1_2.0.0.zip')).toBe(
80+
false,
81+
);
82+
});
83+
84+
it('rejects non-zip file', () => {
85+
expect(
86+
isValidNrf91x1FirmwareName('mfw_nrf91x1_2.0.0.tar'),
87+
).toBe(false);
88+
});
89+
90+
it('rejects nRF9160 firmware names', () => {
91+
expect(
92+
isValidNrf91x1FirmwareName('mfw_nrf9160_1.1.0.zip'),
93+
).toBe(false);
94+
});
95+
});
96+
});
97+
});

0 commit comments

Comments
 (0)