diff options
| author | Li Zhineng <[email protected]> | 2025-07-02 20:25:02 +0800 |
|---|---|---|
| committer | Li Zhineng <[email protected]> | 2025-07-02 20:25:02 +0800 |
| commit | a3b6429c4818f2688a04e78a55954abf1993feb8 (patch) | |
| tree | f76f65b5e386d05facca531267561a7057396477 /server.test.mjs | |
| parent | 6c131da8eb6e20c6fceed35f548c8c0921239e6b (diff) | |
| download | server-a3b6429c4818f2688a04e78a55954abf1993feb8.tar.gz server-a3b6429c4818f2688a04e78a55954abf1993feb8.zip | |
update data structure
Diffstat (limited to 'server.test.mjs')
| -rw-r--r-- | server.test.mjs | 68 |
1 files changed, 61 insertions, 7 deletions
diff --git a/server.test.mjs b/server.test.mjs index b488b80..259b913 100644 --- a/server.test.mjs +++ b/server.test.mjs @@ -10,7 +10,21 @@ const baseUrl = `http://${hostname}:${port}` let server = null const createDevice = async (mac, key) => { - const response = await fetch(`${baseUrl}/eagle?mac=${mac}&key=${key}`) + const params = new URLSearchParams({ + source: 5, + reqid: '0000000000', + eagleId: '', + path: 'eagle/GET/genId', + params: JSON.stringify({ + mac, + key, + version: '00.00.00', + isDenoise: 1, + hardVersion: 1 + }), + sig: '00000000000000000000000000000000' + }) + const response = await fetch(`${baseUrl}/eagle?${params.toString()}`) const data = await response.json() return data.data.eagleId } @@ -58,9 +72,23 @@ test('current time endpoint', async () => { }) test('device registration endpoint', async () => { - const stubMacAddress = '00:00:00:00:00' + const stubMacAddress = '0000000000' const stubKey = '00000000000000000000000000000000' - const res = await fetch(`${baseUrl}/eagle?mac=${stubMacAddress}&key=${stubKey}`) + const params = new URLSearchParams({ + source: 5, + reqid: '0000000000', + eagleId: '', + path: 'eagle/GET/genId', + params: JSON.stringify({ + mac: stubMacAddress, + key: stubKey, + version: '00.00.00', + isDenoise: 1, + hardVersion: 1 + }), + sig: '00000000000000000000000000000000' + }) + const res = await fetch(`${baseUrl}/eagle?${params.toString()}`) assert.strictEqual(res.status, 200) assert.strictEqual(res.headers.get('content-type'), 'application/json') const data = await res.json() @@ -70,20 +98,46 @@ test('device registration endpoint', async () => { test('device registration endpoint returns bad request if missing mac address', async () => { const stubKey = '00000000000000000000000000000000' - const res = await fetch(`${baseUrl}/eagle?key=${stubKey}`) + const params = new URLSearchParams({ + source: 5, + reqid: '0000000000', + eagleId: '', + path: 'eagle/GET/genId', + params: JSON.stringify({ + key: stubKey, + version: '00.00.00', + isDenoise: 1, + hardVersion: 1 + }), + sig: '00000000000000000000000000000000' + }) + const res = await fetch(`${baseUrl}/eagle?${params.toString()}`) assert.strictEqual(res.status, 400) assert.strictEqual(res.headers.get('content-type'), 'application/json') }) test('device registration endpoint returns bad request if missing encryption key', async () => { - const stubMacAddress = '00:00:00:00:00' - const res = await fetch(`${baseUrl}/eagle?mac=${stubMacAddress}`) + const stubMacAddress = '0000000000' + const params = new URLSearchParams({ + source: 5, + reqid: '0000000000', + eagleId: '', + path: 'eagle/GET/genId', + params: JSON.stringify({ + mac: stubMacAddress, + version: '00.00.00', + isDenoise: 1, + hardVersion: 1 + }), + sig: '00000000000000000000000000000000' + }) + const res = await fetch(`${baseUrl}/eagle?${params.toString()}`) assert.strictEqual(res.status, 400) assert.strictEqual(res.headers.get('content-type'), 'application/json') }) test('exchange endpoint', async () => { - const stubMacAddress = '00:00:00:00:00' + const stubMacAddress = '0000000000' const stubKey = '00000000000000000000000000000000' const deviceId = await createDevice(stubMacAddress, stubKey) |
