Welcome to mirror list, hosted at ThFree Co, Russian Federation.

adduser-always-auth.js « tap « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6a451b451c3c62090eaa5d525e4479581e4c7a2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var fs = require("fs")
var path = require("path")
var rimraf = require("rimraf")
var mr = require("npm-registry-mock")

var test = require("tap").test
var common = require("../common-tap.js")

var opts = {cwd : __dirname}
var outfile = path.resolve(__dirname, "_npmrc")
var responses = {
  "Username" : "u\n",
  "Password" : "p\n",
  "Email"    : "u@p.me\n"
}

function mocks(server) {
  server.filteringRequestBody(function (r) {
    if (r.match(/\"_id\":\"org\.couchdb\.user:u\"/)) {
      return "auth"
    }
  })
  server.put("/-/user/org.couchdb.user:u", "auth")
    .reply(201, {username : "u", password : "p", email : "u@p.me"})
}

test("npm login", function (t) {
  mr({port : common.port, plugin : mocks}, function (er, s) {
    var runner = common.npm(
    [
      "login",
      "--registry", common.registry,
      "--loglevel", "silent",
      "--userconfig", outfile
    ],
    opts,
    function (err, code) {
      t.notOk(code, "exited OK")
      t.notOk(err, "no error output")
      var config = fs.readFileSync(outfile, "utf8")
      t.like(config, /:always-auth=false/, "always-auth is scoped and false (by default)")
      s.close()
      rimraf(outfile, function (err) {
        t.ifError(err, "removed config file OK")
        t.end()
      })
    })

    var o = "", e = "", remaining = Object.keys(responses).length
    runner.stdout.on("data", function (chunk) {
      remaining--
      o += chunk

      var label = chunk.toString("utf8").split(":")[0]
      runner.stdin.write(responses[label])

      if (remaining === 0) runner.stdin.end()
    })
    runner.stderr.on("data", function (chunk) { e += chunk })
  })
})

test("npm login --always-auth", function (t) {
  mr({port : common.port, plugin : mocks}, function (er, s) {
    var runner = common.npm(
    [
      "login",
      "--registry", common.registry,
      "--loglevel", "silent",
      "--userconfig", outfile,
      "--always-auth"
    ],
    opts,
    function (err, code) {
      t.notOk(code, "exited OK")
      t.notOk(err, "no error output")
      var config = fs.readFileSync(outfile, "utf8")
      t.like(config, /:always-auth=true/, "always-auth is scoped and true")
      s.close()
      rimraf(outfile, function (err) {
        t.ifError(err, "removed config file OK")
        t.end()
      })
    })

    var o = "", e = "", remaining = Object.keys(responses).length
    runner.stdout.on("data", function (chunk) {
      remaining--
      o += chunk

      var label = chunk.toString("utf8").split(":")[0]
      runner.stdin.write(responses[label])

      if (remaining === 0) runner.stdin.end()
    })
    runner.stderr.on("data", function (chunk) { e += chunk })
  })
})

test("npm login --no-always-auth", function (t) {
  mr({port : common.port, plugin : mocks}, function (er, s) {
    var runner = common.npm(
    [
      "login",
      "--registry", common.registry,
      "--loglevel", "silent",
      "--userconfig", outfile,
      "--no-always-auth"
    ],
    opts,
    function (err, code) {
      t.notOk(code, "exited OK")
      t.notOk(err, "no error output")
      var config = fs.readFileSync(outfile, "utf8")
      t.like(config, /:always-auth=false/, "always-auth is scoped and false")
      s.close()
      rimraf(outfile, function (err) {
        t.ifError(err, "removed config file OK")
        t.end()
      })
    })

    var o = "", e = "", remaining = Object.keys(responses).length
    runner.stdout.on("data", function (chunk) {
      remaining--
      o += chunk

      var label = chunk.toString("utf8").split(":")[0]
      runner.stdin.write(responses[label])

      if (remaining === 0) runner.stdin.end()
    })
    runner.stderr.on("data", function (chunk) { e += chunk })
  })
})


test("cleanup", function (t) {
  rimraf.sync(outfile)
  t.pass("cleaned up")
  t.end()
})