• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

suculent / thinx-device-api / #252646768

01 Nov 2025 03:31PM UTC coverage: 46.298% (-25.7%) from 71.971%
#252646768

push

suculent
testing upgraded mqtt package

1123 of 3470 branches covered (32.36%)

Branch coverage included in aggregate %.

5324 of 10455 relevant lines covered (50.92%)

4.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.16
/spec/jasmine/ZZ-RouterAPIKeySpec.js
1
/* Router integration test only; does not have to cover full unit functionality. */
2

3
const THiNX = require("../../thinx-core.js");
1✔
4

5
let chai = require('chai');
1✔
6
var expect = require('chai').expect;
1✔
7
let chaiHttp = require('chai-http');
1✔
8
chai.use(chaiHttp);
1✔
9

10
//
11
// Unauthenticated
12
//
13

14
let thx;
15
let agent;
16
let jwt;
17

18
describe("API Keys (noauth)", function () {
1✔
19

20
    beforeAll((done) => {
1✔
21
        console.log(`🚸 [chai] >>> running API Keys (noauth) spec`);
1✔
22
        thx = new THiNX();
1✔
23
        thx.init(() => {
1✔
24
            agent = chai.request.agent(thx.app);
×
25
            agent
×
26
                .post('/api/login')
27
                .send({ username: 'dynamic', password: 'dynamic', remember: false })
28
                .catch((e) => { console.log(e); })
×
29
                .then(function (res) {
30
                    console.log(`🚸 [chai] beforeAll POST /api/login (valid) response: ${res}`);
×
31
                    expect(res).to.have.cookie('x-thx-core');
×
32
                    let body = JSON.parse(res.text);
×
33
                    jwt = 'Bearer ' + body.access_token;
×
34
                    done();
×
35
                });
36
        });
37
    });
38

39

40

41
    // create
42
    it("POST /api/user/apikey", function (done) {
1✔
43
        chai.request(thx.app)
×
44
            .post('/api/user/apikey')
45
            .send({
46
                'alias': 'mock-apikey-alias'
47
            })
48
            .end((err, res) => {
49
                expect(res.status).to.equal(401);
×
50
                done();
×
51
            });
52
    }, 30000);
53

54
    // revoke
55
    it("POST /api/user/apikey/revoke", function (done) {
1✔
56
        chai.request(thx.app)
×
57
            .post('/api/user/apikey/revoke')
58
            .send({
59
                'alias': 'mock-apikey-alias'
60
            })
61
            .end((err, res) => {
62
                expect(res.status).to.equal(401);
×
63
                done();
×
64
            });
65
    }, 30000);
66

67
    // list
68
    it("GET /api/user/apikey/list", function (done) {
1✔
69
        chai.request(thx.app)
×
70
            .get('/api/user/apikey/list')
71
            .end((err, res) => {
72
                expect(res.status).to.equal(401);
×
73
                done();
×
74
            });
75
    }, 30000);
76
});
77

78
//
79
// Authenticated
80
//
81

82

83
describe("API Keys (JWT)", function () {
1✔
84

85
    afterAll((done) => {
1✔
86
        agent.close();
1✔
87
        console.log(`🚸 [chai] <<< completed API Keys (noauth) spec`);
×
88
        done();
×
89
    });
90

91
    var created_api_key = null;
1✔
92
    var created_api_key_2 = null;
1✔
93

94
    // create
95
    it("POST /api/user/apikey (1)", function (done) {
1✔
96
        chai.request(thx.app)
1✔
97
            .post('/api/user/apikey')
98
            .set('Authorization', jwt)
99
            .send({
100
                'alias': 'mock-apikey-alias'
101
            })
102
            .end((err, res) => {
103
                //  {"success":true,"api_key":"9b7bd4f4eacf63d8453b32dbe982eea1fb8bbc4fc8e3bcccf2fc998f96138629","hash":"0a920b2e99a917a04d7961a28b49d05524d10cd8bdc2356c026cfc1c280ca22c"}
104
                expect(res.status).to.equal(200);
×
105
                let j = JSON.parse(res.text);
×
106
                expect(j.success).to.equal(true);
×
107
                expect(j.response.api_key).to.be.a('string');
×
108
                expect(j.response.hash).to.be.a('string');
×
109
                created_api_key = j.response.hash;
×
110
                console.log("[spec] saving apikey (1)", j.response.api_key);
×
111
                done();
×
112
            });
113
    }, 30000);
114

115
    it("POST /api/user/apikey (2)", function (done) {
1✔
116
        chai.request(thx.app)
1✔
117
            .post('/api/user/apikey')
118
            .set('Authorization', jwt)
119
            .send({
120
                'alias': 'mock-apikey-alias-2'
121
            })
122
            .end((err, res) => {
123
                expect(res.status).to.equal(200);
×
124
                let j = JSON.parse(res.text);
×
125
                expect(j.success).to.equal(true);
×
126
                expect(j.response.api_key).to.be.a('string');
×
127
                expect(j.response.hash).to.be.a('string');
×
128
                console.log("[spec] saving apikey (2)", j.hash);
×
129
                created_api_key_2 = j.hash;
×
130
                done();
×
131
            });
132
    }, 30000);
133

134
    it("POST /api/user/apikey (3)", function (done) {
1✔
135
        chai.request(thx.app)
1✔
136
            .post('/api/user/apikey')
137
            .set('Authorization', jwt)
138
            .send({
139
                'alias': 'mock-apikey-alias-3'
140
            })
141
            .end((err, res) => {
142
                expect(res.status).to.equal(200);
×
143
                let j = JSON.parse(res.text);
×
144
                expect(j.success).to.equal(true);
×
145
                expect(j.response.api_key).to.be.a('string');
×
146
                expect(j.response.hash).to.be.a('string');
×
147
                done();
×
148
            });
149
    }, 30000);
150

151
    // revoke
152
    it("POST /api/user/apikey/revoke (single)", function (done) {
1✔
153
        expect(created_api_key).not.to.be.null;
1✔
154
        chai.request(thx.app)
×
155
            .post('/api/user/apikey/revoke')
156
            .set('Authorization', jwt)
157
            .send({
158
                'fingerprint': created_api_key
159
            })
160
            .end((err, res) => {
161
                expect(res.status).to.equal(200);
×
162
                let j = JSON.parse(res.text);
×
163
                expect(j.success).to.equal(true);
×
164
                expect(j.response).to.be.an('array');
×
165
                console.log(`🚸 [chai] API Keys in revocation:", ${JSON.stringify(j)} from res ${res.text}`);
×
166
                //expect(aks.length >= 1);
167
                done();
×
168
            });
169
    }, 30000);
170

171
    it("POST /api/user/apikey/revoke (multiple, fault)", function (done) {
1✔
172
        expect(created_api_key_2).not.to.be.null;
1✔
173
        chai.request(thx.app)
×
174
            .post('/api/user/apikey/revoke')
175
            .set('Authorization', jwt)
176
            .send({
177
                'fingerprints': created_api_key_2
178
            })
179
            .end((err, res) => {
180
                //  {"revoked":["7663ca65a23d759485fa158641727597256fd7eac960941fbb861ab433ab056f"],"success":true}
181
                console.log(`🚸 [chai] POST /api/user/apikey/revoke (multiple) response: ${res.text}, status ${res.status}`);
×
182
                expect(res.status).to.equal(200);
×
183
                let j = JSON.parse(res.text);
×
184
                expect(j.success).to.equal(true);
×
185
                expect(j.response).to.be.an('array');
×
186
                expect(j.response.length).to.equal(0);
×
187
                done();
×
188
            });
189
    }, 30000);
190

191
    it("POST /api/user/apikey/revoke (multiple)", function (done) {
1✔
192
        expect(created_api_key_2).not.to.be.null;
1✔
193
        chai.request(thx.app)
×
194
            .post('/api/user/apikey/revoke')
195
            .set('Authorization', jwt)
196
            .send({
197
                'fingerprints': [created_api_key_2]
198
            })
199
            .end((err, res) => {
200
                //  {"revoked":["7663ca65a23d759485fa158641727597256fd7eac960941fbb861ab433ab056f"],"success":true}
201
                console.log(`🚸 [chai] POST /api/user/apikey/revoke (multiple) response: ${res.text}, status ${res.status}`);
×
202
                expect(res.status).to.equal(200);
×
203
                let j = JSON.parse(res.text);
×
204
                expect(j.success).to.equal(true);
×
205
                expect(j.response).to.be.an('array');
×
206
                // TODO: fixme: does not delete anything... expect(j.revoked.length).to.equal(1);
207
                done();
×
208
            });
209
    }, 30000);
210

211
    // list
212
    it("GET /api/user/apikey/list", function (done) {
1✔
213
        chai.request(thx.app)
1✔
214
            .get('/api/user/apikey/list')
215
            .set('Authorization', jwt)
216
            .end((err, res) => {
217
                expect(res.status).to.equal(200);
×
218
                let j = JSON.parse(res.text);
×
219
                expect(j.success).to.equal(true);
×
220
                expect(j.response).to.be.an('array');
×
221
                expect(j.response.length >= 1);
×
222
                done();
×
223
            });
224
    }, 30000);
225

226
    // API v2
227

228
    it("POST /api/v2/apikey", function (done) {
1✔
229
        chai.request(thx.app)
1✔
230
            .post('/api/v2/apikey')
231
            .set('Authorization', jwt)
232
            .send({
233
                'alias': 'mock-apikey-alias-4'
234
            })
235
            .end((err, res) => {
236
                expect(res.status).to.equal(200);
×
237
                let j = JSON.parse(res.text);
×
238
                expect(j.success).to.equal(true);
×
239
                expect(j.response.api_key).to.be.a('string');
×
240
                expect(j.response.hash).to.be.a('string');
×
241
                done();
×
242
            });
243
    }, 30000);
244

245
    it("GET /api/v2/apikey", function (done) {
1✔
246
        chai.request(thx.app)
1✔
247
            .get('/api/v2/apikey')
248
            .set('Authorization', jwt)
249
            .end((err, res) => {
250
                expect(res.status).to.equal(200);
×
251
                let j = JSON.parse(res.text);
×
252
                expect(j.success).to.equal(true);
×
253
                expect(j.response).to.be.an('array');
×
254
                expect(j.response.length >= 1);
×
255
                done();
×
256
            });
257
    }, 30000);
258

259
    it("DELETE /api/v2/apikey", function (done) {
1✔
260
        expect(created_api_key).not.to.be.null;
1✔
261
        chai.request(thx.app)
×
262
            .delete('/api/v2/apikey')
263
            .set('Authorization', jwt)
264
            .send({
265
                'fingerprint': 'mock-apikey-alias-4'
266
            })
267
            .end((err, res) => {
268
                expect(res.status).to.equal(200);
×
269
                let j = JSON.parse(res.text);
×
270
                expect(j.success).to.equal(true);
×
271
                expect(j.response).to.be.an('array');
×
272
                console.log(`🚸 [chai] API Keys in V2 revocation:", ${JSON.stringify(j)} from res ${res.text}`);
×
273
                //expect(aks.length >= 1);
274
                done();
×
275
            });
276
    }, 30000);
277

278
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc