Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
43095a61
Commit
43095a61
authored
Aug 30, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests and refactor middleware
parent
c6d13e36
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
4 deletions
+35
-4
config/initializers/etag_caching.rb
config/initializers/etag_caching.rb
+0
-1
config/initializers/jira.rb
config/initializers/jira.rb
+3
-0
lib/gitlab/jira/middleware.rb
lib/gitlab/jira/middleware.rb
+7
-3
spec/lib/gitlab/jira/middleware_spec.rb
spec/lib/gitlab/jira/middleware_spec.rb
+25
-0
No files found.
config/initializers/etag_caching.rb
View file @
43095a61
...
...
@@ -2,4 +2,3 @@
# in the middleware stack, because it tracks events with
# GitLab Performance Monitoring
Rails
.
application
.
config
.
middleware
.
use
(
Gitlab
::
EtagCaching
::
Middleware
)
Rails
.
application
.
config
.
middleware
.
use
(
Gitlab
::
Jira
::
Middleware
)
config/initializers/jira.rb
0 → 100644
View file @
43095a61
# Treats JIRA DVCS user agent requests in order to be successfully handled
# by our API.
Rails
.
application
.
config
.
middleware
.
use
(
Gitlab
::
Jira
::
Middleware
)
lib/gitlab/jira/middleware.rb
View file @
43095a61
...
...
@@ -6,12 +6,16 @@ module Gitlab
end
def
call
(
env
)
return
@app
.
call
(
env
)
unless
/JIRA DVCS Connector/
.
match
(
env
[
'HTTP_USER_AGENT'
])
env
[
'HTTP_AUTHORIZATION'
]
=
env
[
'HTTP_AUTHORIZATION'
].
sub
(
'token'
,
'Bearer'
)
env
[
'HTTP_AUTHORIZATION'
].
sub!
(
'token'
,
'Bearer'
)
if
jira_dvcs_connector?
(
env
)
@app
.
call
(
env
)
end
private
def
jira_dvcs_connector?
(
env
)
/JIRA DVCS Connector/
.
match
(
env
[
'HTTP_USER_AGENT'
])
end
end
end
end
spec/lib/gitlab/jira/middleware_spec.rb
0 → 100644
View file @
43095a61
require
'spec_helper'
describe
Gitlab
::
Jira
::
Middleware
do
let
(
:app
)
{
double
(
:app
)
}
let
(
:middleware
)
{
described_class
.
new
(
app
)
}
describe
'#call'
do
it
'adjusts HTTP_AUTHORIZATION env when request from JIRA DVCS user agent'
do
user_agent
=
'JIRA DVCS Connector Vertigo/5.0.0-D20170810T012915'
expect
(
app
).
to
receive
(
:call
).
with
(
'HTTP_USER_AGENT'
=>
user_agent
,
'HTTP_AUTHORIZATION'
=>
'Bearer hash-123'
)
middleware
.
call
(
'HTTP_USER_AGENT'
=>
user_agent
,
'HTTP_AUTHORIZATION'
=>
'token hash-123'
)
end
it
'does not change HTTP_AUTHORIZATION env when request is not from JIRA DVCS user agent'
do
env
=
{
'HTTP_USER_AGENT'
=>
'Mozilla/5.0'
,
'HTTP_AUTHORIZATION'
=>
'token hash-123'
}
expect
(
app
).
to
receive
(
:call
).
with
(
env
)
middleware
.
call
(
env
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment