FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
basic-auth-connect/test.js at master · expressjs/basic-auth-connect · GitHub
expressjs
/
basic-auth-connect
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
31
Star
134
Code
Issues
1
Pull requests
8
Actions
Projects
Wiki
Security and quality
1
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
basic-auth-connect
/
test.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
117 lines (95 loc) · 2.84 KB
Breadcrumbs
basic-auth-connect
/
test.js
Copy path
File metadata and controls
117 lines (95 loc) · 2.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
var
request
=
require
(
'supertest'
)
;
var
connect
=
require
(
'connect'
)
;
var
basicAuth
=
require
(
'./'
)
;
function
test
(
app
,
signature
)
{
describe
(
signature
,
function
(
)
{
describe
(
'when missing Authorization'
,
function
(
)
{
it
(
'should respond with 401 and WWW-Authenticate'
,
function
(
done
)
{
request
(
app
)
.
get
(
'/'
)
.
end
(
function
(
err
,
res
)
{
res
.
statusCode
.
should
.
equal
(
401
)
;
res
.
headers
[
'www-authenticate'
]
.
should
.
equal
(
'Basic realm="Authorization Required"'
)
;
done
(
)
;
}
)
;
}
)
}
)
describe
(
'when valid'
,
function
(
)
{
it
(
'should next()'
,
function
(
done
)
{
request
(
app
)
.
get
(
'/'
)
.
set
(
'Authorization'
,
'Basic dGo6dG9iaTpsZWFybmJvb3N0'
)
.
end
(
function
(
err
,
res
)
{
res
.
statusCode
.
should
.
equal
(
200
)
;
res
.
text
.
should
.
equal
(
'secret!'
)
;
done
(
)
;
}
)
;
}
)
}
)
describe
(
'when invalid credentials'
,
function
(
)
{
it
(
'should respond with 401'
,
function
(
done
)
{
request
(
app
)
.
get
(
'/'
)
.
set
(
'Authorization'
,
'Basic dGo69iaQ=='
)
.
end
(
function
(
err
,
res
)
{
res
.
statusCode
.
should
.
equal
(
401
)
;
res
.
headers
[
'www-authenticate'
]
.
should
.
equal
(
'Basic realm="Authorization Required"'
)
;
res
.
text
.
should
.
equal
(
'Unauthorized'
)
;
done
(
)
;
}
)
;
}
)
}
)
describe
(
'when authorization header is not Basic'
,
function
(
)
{
it
(
'should respond with 400'
,
function
(
done
)
{
request
(
app
)
.
get
(
'/'
)
.
set
(
'Authorization'
,
'Digest dGo69iaQ=='
)
.
end
(
function
(
err
,
res
)
{
res
.
statusCode
.
should
.
equal
(
400
)
;
res
.
text
.
should
.
match
(
/
B
a
d
R
e
q
u
e
s
t
/
)
;
done
(
)
;
}
)
;
}
)
}
)
describe
(
'when authorization header is malformed - contains only one part'
,
function
(
)
{
it
(
'should respond with 400'
,
function
(
done
)
{
request
(
app
)
.
get
(
'/'
)
.
set
(
'Authorization'
,
'invalid'
)
.
end
(
function
(
err
,
res
)
{
res
.
statusCode
.
should
.
equal
(
400
)
;
res
.
text
.
should
.
match
(
/
B
a
d
R
e
q
u
e
s
t
/
)
;
done
(
)
;
}
)
;
}
)
}
)
}
)
}
var
app
=
connect
(
)
;
app
.
use
(
basicAuth
(
'tj'
,
'tobi:learnboost'
)
)
;
app
.
use
(
function
(
req
,
res
,
next
)
{
req
.
user
.
should
.
equal
(
'tj'
)
;
res
.
end
(
'secret!'
)
;
}
)
;
test
(
app
,
'basicAuth(user, pass)'
)
;
app
=
connect
(
)
;
app
.
use
(
basicAuth
(
function
(
user
,
pass
)
{
return
'tj'
==
user
&&
'tobi:learnboost'
==
pass
;
}
)
)
;
app
.
use
(
function
(
req
,
res
,
next
)
{
req
.
user
.
should
.
equal
(
'tj'
)
;
res
.
end
(
'secret!'
)
;
}
)
;
test
(
app
,
'basicAuth(callback)'
)
;
app
=
connect
(
)
;
app
.
use
(
basicAuth
(
function
(
user
,
pass
,
fn
)
{
var
ok
=
'tj'
==
user
&&
'tobi:learnboost'
==
pass
;
fn
(
null
,
ok
?
{
name
:
'tj'
}
:
null
)
;
}
)
)
;
app
.
use
(
function
(
req
,
res
,
next
)
{
req
.
user
.
name
.
should
.
equal
(
'tj'
)
;
res
.
end
(
'secret!'
)
;
}
)
;
test
(
app
,
'basicAuth(callback) async'
)
;
Back
|
FazBrowse Home
|
New Git URL