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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
26d15a89
Commit
26d15a89
authored
Aug 01, 2017
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Mattermost integration
parent
dbadf5a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
9 deletions
+28
-9
changelogs/unreleased/mattermost_fixes.yml
changelogs/unreleased/mattermost_fixes.yml
+4
-0
lib/mattermost/session.rb
lib/mattermost/session.rb
+20
-6
spec/lib/mattermost/session_spec.rb
spec/lib/mattermost/session_spec.rb
+4
-3
No files found.
changelogs/unreleased/mattermost_fixes.yml
0 → 100644
View file @
26d15a89
---
title
:
Fix Mattermost integration
merge_request
:
author
:
lib/mattermost/session.rb
View file @
26d15a89
...
@@ -36,11 +36,12 @@ module Mattermost
...
@@ -36,11 +36,12 @@ module Mattermost
def
with_session
def
with_session
with_lease
do
with_lease
do
raise
Mattermost
::
NoSessionError
unless
create
create
begin
begin
yield
self
yield
self
rescue
Errno
::
ECONNREFUSED
rescue
Errno
::
ECONNREFUSED
=>
e
Rails
.
logger
.
error
(
e
.
message
+
"
\n
"
+
e
.
backtrace
.
join
(
"
\n
"
))
raise
Mattermost
::
NoSessionError
raise
Mattermost
::
NoSessionError
ensure
ensure
destroy
destroy
...
@@ -85,10 +86,12 @@ module Mattermost
...
@@ -85,10 +86,12 @@ module Mattermost
private
private
def
create
def
create
r
eturn
unless
oauth_uri
r
aise
Mattermost
::
NoSessionError
unless
oauth_uri
r
eturn
unless
token_uri
r
aise
Mattermost
::
NoSessionError
unless
token_uri
@token
=
request_token
@token
=
request_token
raise
Mattermost
::
NoSessionError
unless
@token
@headers
=
{
@headers
=
{
Authorization
:
"Bearer
#{
@token
}
"
Authorization
:
"Bearer
#{
@token
}
"
}
}
...
@@ -106,11 +109,16 @@ module Mattermost
...
@@ -106,11 +109,16 @@ module Mattermost
@oauth_uri
=
nil
@oauth_uri
=
nil
response
=
get
(
"/api/v3/oauth/gitlab/login"
,
follow_redirects:
false
)
response
=
get
(
"/api/v3/oauth/gitlab/login"
,
follow_redirects:
false
)
return
unless
300
<=
response
.
code
&&
response
.
code
<
400
return
unless
(
300
...
400
)
===
response
.
code
redirect_uri
=
response
.
headers
[
'location'
]
redirect_uri
=
response
.
headers
[
'location'
]
return
unless
redirect_uri
return
unless
redirect_uri
oauth_cookie
=
parse_cookie
(
response
)
@headers
=
{
Cookie
:
oauth_cookie
.
to_cookie_string
}
@oauth_uri
=
URI
.
parse
(
redirect_uri
)
@oauth_uri
=
URI
.
parse
(
redirect_uri
)
end
end
...
@@ -124,7 +132,7 @@ module Mattermost
...
@@ -124,7 +132,7 @@ module Mattermost
def
request_token
def
request_token
response
=
get
(
token_uri
,
follow_redirects:
false
)
response
=
get
(
token_uri
,
follow_redirects:
false
)
if
200
<=
response
.
code
&&
response
.
code
<
400
if
(
200
...
400
)
===
response
.
code
response
.
headers
[
'token'
]
response
.
headers
[
'token'
]
end
end
end
end
...
@@ -156,5 +164,11 @@ module Mattermost
...
@@ -156,5 +164,11 @@ module Mattermost
rescue
Errno
::
ECONNREFUSED
=>
e
rescue
Errno
::
ECONNREFUSED
=>
e
raise
Mattermost
::
ConnectionError
.
new
(
e
.
message
)
raise
Mattermost
::
ConnectionError
.
new
(
e
.
message
)
end
end
def
parse_cookie
(
response
)
cookie_hash
=
CookieHash
.
new
response
.
get_fields
(
'Set-Cookie'
).
each
{
|
c
|
cookie_hash
.
add_cookies
(
c
)
}
cookie_hash
end
end
end
end
end
spec/lib/mattermost/session_spec.rb
View file @
26d15a89
...
@@ -20,9 +20,10 @@ describe Mattermost::Session, type: :request do
...
@@ -20,9 +20,10 @@ describe Mattermost::Session, type: :request do
describe
'#with session'
do
describe
'#with session'
do
let
(
:location
)
{
'http://location.tld'
}
let
(
:location
)
{
'http://location.tld'
}
let
(
:cookie_header
)
{
'MMOAUTH=taskik8az7rq8k6rkpuas7htia; Path=/;'
}
let!
(
:stub
)
do
let!
(
:stub
)
do
WebMock
.
stub_request
(
:get
,
"
#{
mattermost_url
}
/api/v3/oauth/gitlab/login"
)
WebMock
.
stub_request
(
:get
,
"
#{
mattermost_url
}
/api/v3/oauth/gitlab/login"
)
.
to_return
(
headers:
{
'location'
=>
location
},
status:
307
)
.
to_return
(
headers:
{
'location'
=>
location
,
'Set-Cookie'
=>
cookie_header
},
status:
307
)
end
end
context
'without oauth uri'
do
context
'without oauth uri'
do
...
@@ -34,9 +35,9 @@ describe Mattermost::Session, type: :request do
...
@@ -34,9 +35,9 @@ describe Mattermost::Session, type: :request do
context
'with oauth_uri'
do
context
'with oauth_uri'
do
let!
(
:doorkeeper
)
do
let!
(
:doorkeeper
)
do
Doorkeeper
::
Application
.
create
(
Doorkeeper
::
Application
.
create
(
name:
"GitLab Mattermost"
,
name:
'GitLab Mattermost'
,
redirect_uri:
"
#{
mattermost_url
}
/signup/gitlab/complete
\n
#{
mattermost_url
}
/login/gitlab/complete"
,
redirect_uri:
"
#{
mattermost_url
}
/signup/gitlab/complete
\n
#{
mattermost_url
}
/login/gitlab/complete"
,
scopes:
""
)
scopes:
''
)
end
end
context
'without token_uri'
do
context
'without token_uri'
do
...
...
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