Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
texjs-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Mehren
texjs-web
Commits
d65cbca2
Commit
d65cbca2
authored
Aug 29, 2017
by
Henry Oswald
Browse files
Options
Downloads
Patches
Plain Diff
added csrf acceptence tests
parent
e4afb11e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/acceptance/coffee/RegistrationTests.coffee
+59
-0
59 additions, 0 deletions
test/acceptance/coffee/RegistrationTests.coffee
test/acceptance/coffee/helpers/User.coffee
+13
-1
13 additions, 1 deletion
test/acceptance/coffee/helpers/User.coffee
with
72 additions
and
1 deletion
test/acceptance/coffee/RegistrationTests.coffee
+
59
−
0
View file @
d65cbca2
...
@@ -69,6 +69,65 @@ describe "LoginRateLimit", ->
...
@@ -69,6 +69,65 @@ describe "LoginRateLimit", ->
)
)
describe
"CSRF protection"
,
->
beforeEach
->
@
user
=
new
User
()
@
email
=
"test+
#{
Math
.
random
()
}
@example.com"
@
password
=
"password11"
afterEach
->
@
user
.
full_delete_user
(
@
email
)
it
'should register with the csrf token'
,
(
done
)
->
@
user
.
request
.
get
'/login'
,
(
err
,
res
,
body
)
=>
@
user
.
getCsrfToken
(
error
)
=>
@
user
.
request
.
post
{
url
:
"/register"
json
:
email
:
@
email
password
:
@
password
headers
:
{
"x-csrf-token"
:
@
user
.
csrfToken
}
},
(
error
,
response
,
body
)
=>
expect
(
err
?
).
to
.
equal
false
expect
(
response
.
statusCode
).
to
.
equal
200
done
()
it
'should fail with no csrf token'
,
(
done
)
->
@
user
.
request
.
get
'/login'
,
(
err
,
res
,
body
)
=>
@
user
.
getCsrfToken
(
error
)
=>
@
user
.
request
.
post
{
url
:
"/register"
json
:
email
:
@
email
password
:
@
password
headers
:
{
"x-csrf-token"
:
""
}
},
(
error
,
response
,
body
)
=>
expect
(
response
.
statusCode
).
to
.
equal
403
done
()
it
'should fail with a stale csrf token'
,
(
done
)
->
@
user
.
request
.
get
'/login'
,
(
err
,
res
,
body
)
=>
@
user
.
getCsrfToken
(
error
)
=>
oldCsrfToken
=
@
user
.
csrfToken
@
user
.
request
.
get
'/logout'
,
(
err
,
res
,
body
)
=>
@
user
.
request
.
post
{
url
:
"/register"
json
:
email
:
@
email
password
:
@
password
headers
:
{
"x-csrf-token"
:
oldCsrfToken
}
},
(
error
,
response
,
body
)
=>
expect
(
response
.
statusCode
).
to
.
equal
403
done
()
describe
"LoginViaRegistration"
,
->
describe
"LoginViaRegistration"
,
->
before
(
done
)
->
before
(
done
)
->
...
...
This diff is collapsed.
Click to expand it.
test/acceptance/coffee/helpers/User.coffee
+
13
−
1
View file @
d65cbca2
...
@@ -51,6 +51,17 @@ class User
...
@@ -51,6 +51,17 @@ class User
ensure_admin
:
(
callback
=
(
error
)
->
)
->
ensure_admin
:
(
callback
=
(
error
)
->
)
->
db
.
users
.
update
{
_id
:
ObjectId
(
@
id
)},
{
$set
:
{
isAdmin
:
true
}},
callback
db
.
users
.
update
{
_id
:
ObjectId
(
@
id
)},
{
$set
:
{
isAdmin
:
true
}},
callback
full_delete_user
:
(
email
,
callback
=
(
error
)
->
)
->
db
.
users
.
findOne
{
email
:
email
},
(
error
,
user
)
=>
if
!
user
?
return
callback
()
user_id
=
user
.
_id
db
.
projects
.
remove
owner_ref
:
ObjectId
(
user_id
),
{
multi
:
true
},
(
err
)
->
if
err
?
callback
(
err
)
db
.
users
.
remove
{
_id
:
ObjectId
(
user_id
)},
callback
createProject
:
(
name
,
callback
=
(
error
,
project_id
)
->
)
->
createProject
:
(
name
,
callback
=
(
error
,
project_id
)
->
)
->
@
request
.
post
{
@
request
.
post
{
url
:
"/project/new"
,
url
:
"/project/new"
,
...
@@ -104,9 +115,10 @@ class User
...
@@ -104,9 +115,10 @@ class User
csrfMatches
=
body
.
match
(
"window.csrfToken =
\"
(.*?)
\"
;"
)
csrfMatches
=
body
.
match
(
"window.csrfToken =
\"
(.*?)
\"
;"
)
if
!
csrfMatches
?
if
!
csrfMatches
?
return
callback
(
new
Error
(
"no csrf token found"
))
return
callback
(
new
Error
(
"no csrf token found"
))
@
csrfToken
=
csrfMatches
[
1
]
@
request
=
@
request
.
defaults
({
@
request
=
@
request
.
defaults
({
headers
:
headers
:
"x-csrf-token"
:
csrf
Matches
[
1
]
"x-csrf-token"
:
@
csrf
Token
})
})
callback
()
callback
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment