• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var common = require('../common-tap.js')
2var test = require('tap').test
3var http = require('http')
4
5test('should send referer http header', function (t) {
6  http.createServer(function (q, s) {
7    t.equal(q.headers.referer, 'install foo')
8    s.statusCode = 404
9    s.end(JSON.stringify({error: 'whatever'}))
10    this.close()
11  }).listen(common.port, function () {
12    var reg = 'http://localhost:' + common.port
13    var args = [ 'install', 'foo', '--registry', reg ]
14    common.npm(args, {}, function (er, code) {
15      if (er) {
16        throw er
17      }
18      // should not have ended nicely, since we returned an error
19      t.ok(code)
20      t.end()
21    })
22  })
23})
24
25test('should redact user secret from hook add command', function (t) {
26  http.createServer(function (q, s) {
27    t.equal(q.headers.referer, 'hook add ~zkat [REDACTED] [REDACTED]')
28    s.statusCode = 204
29    s.end()
30    this.close()
31  }).listen(common.port, function () {
32    var reg = `http://localhost:${common.port}`
33    var args = [ 'hook', 'add', '~zkat', 'https://example.com', 'sekrit', '--registry', reg ]
34    common.npm(args, {}, function (er, code) {
35      if (er) {
36        throw er
37      }
38      // should not have ended nicely, since we returned an error
39      t.ok(code)
40      t.end()
41    })
42  })
43})
44
45test('should redact user secret from hook up command', function (t) {
46  http.createServer(function (q, s) {
47    t.equal(q.headers.referer, 'hook up ~zkat [REDACTED] [REDACTED]')
48    s.statusCode = 204
49    s.end()
50    this.close()
51  }).listen(common.port, function () {
52    var reg = `http://localhost:${common.port}`
53    var args = [ 'hook', 'up', '~zkat', 'https://example.com', 'sekrit', '--registry', reg ]
54    common.npm(args, {}, function (er, code) {
55      if (er) {
56        throw er
57      }
58      // should not have ended nicely, since we returned an error
59      t.ok(code)
60      t.end()
61    })
62  })
63})
64
65test('should redact user secret from hook update command', function (t) {
66  http.createServer(function (q, s) {
67    t.equal(q.headers.referer, 'hook update ~zkat [REDACTED] [REDACTED]')
68    s.statusCode = 204
69    s.end()
70    this.close()
71  }).listen(common.port, function () {
72    var reg = `http://localhost:${common.port}`
73    var args = [ 'hook', 'update', '~zkat', 'https://example.com', 'sekrit', '--registry', reg ]
74    common.npm(args, {}, function (er, code) {
75      if (er) {
76        throw er
77      }
78      // should not have ended nicely, since we returned an error
79      t.ok(code)
80      t.end()
81    })
82  })
83})
84