1 | var assert = require('assert')
|
2 | , parse_htpasswd = require('../utils').parse_htpasswd
|
3 | , verify_password = require('../utils').verify_password
|
4 | , add_user_to_htpasswd = require('../utils').add_user_to_htpasswd
|
5 |
|
6 | describe('parse_htpasswd', function() {
|
7 |
|
8 | })
|
9 |
|
10 | describe('verify_password', function() {
|
11 | it('should verify plain', function() {
|
12 | assert(verify_password('user', 'pass', '{PLAIN}pass'))
|
13 | assert(!verify_password('user', 'p', '{PLAIN}pass'))
|
14 | })
|
15 | it('should verify sha', function() {
|
16 | assert(verify_password('user', 'pass', '{SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ='))
|
17 | assert(!verify_password('user', 'p', '{SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ='))
|
18 | })
|
19 | it('should verify crypt', function() {
|
20 | assert(verify_password('user', 'pass', 'ulINxGnqObi36'))
|
21 | assert(!verify_password('user', 'p', 'ulINxGnqObi36'))
|
22 | })
|
23 | it('should verify crypt-sha', function() {
|
24 | assert(verify_password('user', 'pass', '$6$Qx0eNSKPbxocgA==$ugjO0.z9yOFiaJXJK4ulvGYIxF/KZBV4lGqasArYPqPPT4orZ6NlnIE5KhtiOVs.5EoWxLg1sjp318G8RpI2x1'))
|
25 | assert(!verify_password('user', 'p', '$6$Qx0eNSKPbxocgA==$ugjO0.z9yOFiaJXJK4ulvGYIxF/KZBV4lGqasArYPqPPT4orZ6NlnIE5KhtiOVs.5EoWxLg1sjp318G8RpI2x1'))
|
26 | })
|
27 | })
|
28 |
|
29 | describe('add_user_to_htpasswd', function() {
|
30 | it('should add user to empty file', function() {
|
31 | var res = add_user_to_htpasswd('', 'user', 'passwd')
|
32 | assert(res.match(/^user:[^:\n]+:autocreated [^\n]+\n$/))
|
33 | })
|
34 |
|
35 | it('should append user / newline checks', function() {
|
36 | var res = add_user_to_htpasswd('testtest', 'user', 'passwd')
|
37 | assert(res.match(/^testtest\nuser:[^:\n]+:autocreated [^\n]+\n$/))
|
38 | var res = add_user_to_htpasswd('testtest\n', 'user', 'passwd')
|
39 | assert(res.match(/^testtest\nuser:[^:\n]+:autocreated [^\n]+\n$/))
|
40 | var res = add_user_to_htpasswd('testtest\n\n', 'user', 'passwd')
|
41 | assert(res.match(/^testtest\n\nuser:[^:\n]+:autocreated [^\n]+\n$/))
|
42 | })
|
43 |
|
44 | it('should not append invalid users', function() {
|
45 | assert.throws(function() {
|
46 | add_user_to_htpasswd('', 'us:er', 'passwd')
|
47 | }, /non-uri-safe/)
|
48 | assert.throws(function() {
|
49 | add_user_to_htpasswd('', 'us\ner', 'passwd')
|
50 | }, /non-uri-safe/)
|
51 | assert.throws(function() {
|
52 | add_user_to_htpasswd('', 'us#er', 'passwd')
|
53 | }, /non-uri-safe/)
|
54 | })
|
55 | })
|
56 |
|