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

suculent / thinx-device-api / #252645614

08 Nov 2023 06:04PM UTC coverage: 71.784% (+66.5%) from 5.266%
#252645614

push

suculent
Merge branch 'main'

* main: (49 commits)
  maintenance release v1.9.2451
  removed services/broker submodule before re-adding
  removed lua-iinspect
  log leak fix
  log cleanup, redeploy after changing expired Rollbar Project Access Tokens
  submodule sync
  version bump, log cleanup and base image update after fixing GitHub OAuth
  dependency updates, fixing github login (has code but different object structure)
  test passes, but parsing fails
  spec fix for staging
  fails in tests, because code is B
  removed json
  fixes
  gpg
  debugging broken github-oauth login
  task renamed
  recent test passed, build stable, adding debug logging only for next refactoring steps
  fix for potent. unlinked github login addRoutes
  recent test passed, build stable, adding debug logging only for next refactoring steps
  github fix
  ...

# Conflicts:
#	package-lock.json
#	package.json

1795 of 3438 branches covered (0.0%)

Branch coverage included in aggregate %.

20 of 51 new or added lines in 6 files covered. (39.22%)

182 existing lines in 5 files now uncovered.

8165 of 10437 relevant lines covered (78.23%)

7.53 hits per line

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

47.83
/lib/thinx/oauth-github.js
1
var axios = require('axios');
1✔
2

3
var events = require('events');
1✔
4
var url = require('url');
1✔
5
var crypto = require('crypto');
1✔
6

7
module.exports = function (opts) {
1✔
8
  if (!opts.callbackURI) opts.callbackURI = '/github/callback';
15!
9
  if (!opts.loginURI) opts.loginURI = '/github/login';
15!
10
  if (typeof opts.scope === 'undefined') opts.scope = 'user';
15!
11
  var state = crypto.randomBytes(8).toString('hex');
15✔
12
  var urlObj = url.parse(opts.baseURL);
15✔
13
  urlObj.pathname = url.resolve(urlObj.pathname, opts.callbackURI);
15✔
14
  var redirectURI = url.format(urlObj);
15✔
15
  var emitter = new events.EventEmitter();
15✔
16

17
  function login(req, resp) {
18
    var u = 'https://github.com/login/oauth/authorize'
1✔
19
      + '?client_id=' + opts.githubClient
20
      + (opts.scope ? '&scope=' + opts.scope : '')
1!
21
      + '&redirect_uri=' + redirectURI
22
      + '&state=' + state
23
      ;
24
    resp.statusCode = 302;
1✔
25
    resp.setHeader('location', u);
1✔
26
    resp.end();
1✔
27
  }
28

29
  function parseResponse(body) {
NEW
30
    const items = body.split("&");
×
NEW
31
    var data = null;
×
NEW
32
    for (item in items) {
×
NEW
33
      const kv = items[0].split("=");
×
NEW
34
      const key = kv[0];
×
NEW
35
      const val = kv[1];
×
NEW
36
      if (key.indexOf("access_token" !== -1)) {
×
NEW
37
        data = val;
×
NEW
38
        break;
×
39
      }
40
    }
NEW
41
    return data;
×
42
  }
43

44
  function callback(req, resp, cb) {
45
    var query = url.parse(req.url, true).query
2✔
46
    var code = query.code
2✔
47
    if (!code || code.length < 4) {
2!
48
      const rbody = resp.body;
2✔
49
      console.log("[debug] [oauth-github] missing or invalid oauth code in ", {query}, {rbody});
2✔
50
      return emitter.emit('error', { error: 'missing or invalid oauth code' }, resp)
2✔
51
    }
52
    var u = 'https://github.com/login/oauth/access_token'
×
53
      + '?client_id=' + opts.githubClient
54
      + '&client_secret=' + opts.githubSecret
55
      + '&code=' + code
56
      + '&state=' + state
57
      ;
58

NEW
59
    (async () => {
×
NEW
60
      try {
×
NEW
61
        const body = await axios.get(u);
×
NEW
62
        console.log("[debug] emitting event token with body", { body });
×
NEW
63
        const data = parseResponse(body.data);
×
NEW
64
        if (data.indexOf("gho_") !== -1) {
×
NEW
65
          emitter.emit('token', data);
×
NEW
66
          if (cb) return cb(null, data);
×
67
        } else {
NEW
68
          console.log("[debug] Invalid GitHub Response:", {body});
×
69
        }
70
      } catch (e) {
NEW
71
        console.log("axios get error:", e);
×
NEW
72
        if (cb) return cb(e);
×
NEW
73
        emitter.emit('error', null, e);
×
74
      }
75
    })()
76
  }
77

78
  emitter.login = login;
15✔
79
  emitter.callback = callback;
15✔
80
  return emitter;
15✔
81
}
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