Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gabriel Monnerat
erp5
Commits
bb9bec34
Commit
bb9bec34
authored
Oct 02, 2017
by
Gabriel Monnerat
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_oauth_google_login: Add test to cover refresh token
parent
6bbdec0a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
bt5/erp5_oauth_google_login/TestTemplateItem/portal_components/test.erp5.testGoogleLogin.py
...mplateItem/portal_components/test.erp5.testGoogleLogin.py
+42
-0
No files found.
bt5/erp5_oauth_google_login/TestTemplateItem/portal_components/test.erp5.testGoogleLogin.py
View file @
bb9bec34
...
...
@@ -26,6 +26,7 @@
##############################################################################
import
uuid
import
oauth2client.client
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
erp5.component.extension
import
GoogleLoginUtility
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
...
...
@@ -87,6 +88,14 @@ def getUserEntry(access_token):
"reference"
:
getUserId
(
None
)
}
def
refreshToken
(
self
,
http
):
self
.
__dict__
.
update
({
"refresh_token"
:
"234"
,
"token_expiry"
:
"2017-10-01T16:06:28Z"
,
"expires_in"
:
3600
})
return
self
GoogleLoginUtility_getAccessTokenFromCode
=
GoogleLoginUtility
.
getAccessTokenFromCode
GoogleLoginUtility_getUserEntry
=
GoogleLoginUtility
.
getUserEntry
...
...
@@ -162,6 +171,39 @@ class TestGoogleLogin(ERP5TypeTestCase):
self
.
assertNotIn
(
"secret_key="
,
location
)
self
.
assertIn
(
"ERP5Site_receiveGoogleCallback"
,
location
)
def
test_refresh_token
(
self
):
original_method
=
oauth2client
.
client
.
OAuth2Credentials
.
refresh
oauth2client
.
client
.
OAuth2Credentials
.
refresh
=
refreshToken
response
=
self
.
portal
.
ERP5Site_receiveGoogleCallback
(
code
=
CODE
)
google_hash
=
self
.
portal
.
REQUEST
.
RESPONSE
.
cookies
.
get
(
"__ac_google_hash"
)[
"value"
]
self
.
assertEqual
(
"b01533abb684a658dc71c81da4e67546"
,
google_hash
)
self
.
assertEqual
(
self
.
portal
.
absolute_url
(),
response
)
cache_dict
=
self
.
portal
.
Base_getBearerToken
(
google_hash
,
"google_server_auth_token_cache_factory"
)
self
.
assertEqual
(
CLIENT_ID
,
cache_dict
[
"client_id"
])
self
.
assertEqual
(
ACCESS_TOKEN
,
cache_dict
[
"access_token"
])
self
.
assertEqual
({
'reference'
:
getUserId
(
None
)},
self
.
portal
.
Base_getBearerToken
(
ACCESS_TOKEN
,
"google_server_auth_token_cache_factory"
)
)
cache_dict
[
"token_response"
][
"expires_in"
]
=
1
self
.
portal
.
Base_setBearerToken
(
google_hash
,
cache_dict
,
"google_server_auth_token_cache_factory"
)
self
.
portal
.
REQUEST
[
"__ac_google_hash"
]
=
google_hash
erp5_google_extractor
=
self
.
portal
.
acl_users
.
erp5_google_extraction
self
.
assertEqual
({
'external_login'
:
getUserId
(
None
),
'login_portal_type'
:
'Google Login'
,
'remote_host'
:
''
,
'remote_address'
:
''
},
erp5_google_extractor
.
extractCredentials
(
self
.
portal
.
REQUEST
))
cache_dict
=
self
.
portal
.
Base_getBearerToken
(
google_hash
,
"google_server_auth_token_cache_factory"
)
self
.
assertEqual
(
"234"
,
cache_dict
[
"refresh_token"
])
self
.
assertEqual
(
3600
,
cache_dict
[
"expires_in"
])
auth2client
.
client
.
OAuth2Credentials
.
refresh
=
original_method
def
test_create_user_in_ERP5Site_createGoogleUserToOAuth
(
self
):
"""
Check if ERP5 set cookie properly after receive code from external service
...
...
Gabriel Monnerat
@gabriel
mentioned in merge request
nexedi/erp5!219 (merged)
·
Oct 02, 2017
mentioned in merge request
nexedi/erp5!219 (merged)
mentioned in merge request nexedi/erp5!219
Toggle commit list
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