summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server.mjs5
-rw-r--r--server.test.mjs68
2 files changed, 63 insertions, 10 deletions
diff --git a/server.mjs b/server.mjs
index ff9d7ba..844430e 100644
--- a/server.mjs
+++ b/server.mjs
@@ -30,10 +30,9 @@ const getTimeControlller = (req, res) => {
const eagleController = (req, res) => {
const [, query] = req.url.split('?')
const params = new URLSearchParams(query)
- const mac = params.get('mac')
- const key = params.get('key')
+ const { mac, key } = JSON.parse(params.get('params') || '{}')
- if (mac === null || key === null) {
+ if (mac === undefined || key === undefined) {
res.writeHead(400, { 'Content-Type': 'application/json' })
res.end('{}\n')
return
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)