]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/legacy-no-auth-leak.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / legacy-no-auth-leak.js
1 'use strict'
2 var test = require('tap').test
3 var common = require('../common-tap.js')
4 var path = require('path')
5 var basepath = path.resolve(__dirname, path.basename(__filename, '.js'))
6 var Tacks = require('tacks')
7 var File = Tacks.File
8 var Dir = Tacks.Dir
9
10 var fixture = new Tacks(
11   Dir({
12     README: File(
13       'just an npm test\n'
14     ),
15     'package.json': File({
16       name: 'npm-test-no-auth-leak',
17       version: '0.0.0',
18       scripts: {
19         test: 'node test.js'
20       }
21     }),
22     '.npmrc': File(
23       'auth=abc',
24       'authCrypt=def',
25       'password=xyz',
26       '//registry.npmjs.org/:_authToken=nopenope'
27     ),
28     'test.js': File(
29       'var authTokenKeys = Object.keys(process.env)\n' +
30       '  .filter(function (key) { return /authToken/.test(key) })\n' +
31       'console.log(JSON.stringify({\n' +
32       '  password: process.env.npm_config__password || null,\n' +
33       '  auth: process.env.npm_config__auth || null,\n' +
34       '  authCrypt: process.env.npm_config__authCrypt || null ,\n' +
35       '  authToken: authTokenKeys && process.env[authTokenKeys[0]] || null\n' +
36       '}))'
37     )
38   })
39 )
40
41 test('setup', function (t) {
42   setup()
43   t.done()
44 })
45
46 test('no-auth-leak', function (t) {
47   common.npm(['test'], {cwd: basepath}, function (err, code, stdout, stderr) {
48     if (err) throw err
49     t.is(code, 0, 'test ran ok')
50     if (stderr) console.log(stderr)
51     var matchResult = /^[^{]*(\{(?:.|\n)*\})[^}]*$/
52     t.like(stdout, matchResult, 'got results with a JSON chunk in them')
53     var stripped = stdout.replace(matchResult, '$1')
54     var result = JSON.parse(stripped)
55     t.is(result.password, null, 'password')
56     t.is(result.auth, null, 'auth')
57     t.is(result.authCrypt, null, 'authCrypt')
58     t.is(result.authToken, null, 'authToken')
59     t.end()
60   })
61 })
62
63 test('cleanup', function (t) {
64   cleanup()
65   t.done()
66 })
67
68 function setup () {
69   cleanup()
70   fixture.create(basepath)
71 }
72
73 function cleanup () {
74   fixture.remove(basepath)
75 }