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
Labels
Merge Requests
144
Merge Requests
144
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
b8d5d6c1
Commit
b8d5d6c1
authored
Oct 03, 2016
by
Gabriel Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_oauth_google_login: Add unit test for Google login in ERP5
parent
5b96aa44
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
258 additions
and
0 deletions
+258
-0
bt5/erp5_oauth_google_login/TestTemplateItem/portal_components/test.erp5.testGoogleLogin.py
...mplateItem/portal_components/test.erp5.testGoogleLogin.py
+134
-0
bt5/erp5_oauth_google_login/TestTemplateItem/portal_components/test.erp5.testGoogleLogin.xml
...plateItem/portal_components/test.erp5.testGoogleLogin.xml
+123
-0
bt5/erp5_oauth_google_login/bt/template_test_id_list
bt5/erp5_oauth_google_login/bt/template_test_id_list
+1
-0
No files found.
bt5/erp5_oauth_google_login/TestTemplateItem/portal_components/test.erp5.testGoogleLogin.py
0 → 100644
View file @
b8d5d6c1
##############################################################################
#
# Copyright (c) 2002-2016 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
import
json
import
httplib
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
erp5.component.extension
import
GoogleLoginUtility
CLIENT_ID
=
"a1b2c3"
SECRET_KEY
=
"3c2ba1"
ACCESS_TOKEN
=
"T1234"
CODE
=
"1234"
class
MockHTTPSConnectionResponse
(
object
):
def
__init__
(
self
):
self
.
status
=
200
def
read
(
self
):
return
json
.
dumps
({
"access_token"
:
ACCESS_TOKEN
})
class
MockHTTPSConnection
:
def
__init__
(
self
,
host
,
timeout
):
assert
host
==
'accounts.google.com'
assert
timeout
==
30
def
request
(
self
,
method
,
url
,
body
,
headers
):
assert
method
==
"POST"
assert
url
==
'/o/oauth2/token'
assert
"client_id=%s"
%
CLIENT_ID
in
body
,
"CLIENT_ID not found %s"
%
body
assert
"client_secret=%s"
%
SECRET_KEY
in
body
,
"SECRET_KEY not found %s"
%
body
assert
"code=%s"
%
CODE
in
body
,
"CODE not found %s"
%
body
def
getresponse
(
self
):
return
MockHTTPSConnectionResponse
()
def
getUserId
(
access_token
):
return
"1234"
httplib
.
HTTPSConnection
=
MockHTTPSConnection
GoogleLoginUtility
.
getUserId
=
getUserId
class
TestGoogleLogin
(
ERP5TypeTestCase
):
def
getTitle
(
self
):
return
"Test Google Login"
def
afterSetUp
(
self
):
"""
This is ran before anything, used to set the environment
"""
system_preference
=
self
.
portal
.
portal_preferences
.
getActiveSystemPreference
()
if
system_preference
is
None
:
system_preference
=
self
.
portal
.
portal_preferences
.
newContent
(
title
=
"Global System Preference"
,
portal_type
=
"System Preference"
)
system_preference
.
enable
()
system_preference
.
edit
(
preferred_google_client_id
=
CLIENT_ID
,
preferred_google_secret_key
=
SECRET_KEY
,
)
self
.
tic
()
def
test_redirect
(
self
):
"""
Check URL generate to redirect to Google
"""
self
.
logout
()
self
.
portal
.
ERP5Site_redirectToGoogleLoginPage
()
location
=
self
.
portal
.
REQUEST
.
RESPONSE
.
getHeader
(
"Location"
)
self
.
assertTrue
(
location
.
startswith
(
"https://accounts.google.com/o/oauth2/auth"
),
location
)
self
.
assertIn
(
"response_type=code"
,
location
)
self
.
assertIn
(
"client_id=%s"
%
CLIENT_ID
,
location
)
self
.
assertNotIn
(
"secret_key="
,
location
)
self
.
assertIn
(
"/ERP5Site_receiveGoogleCallback"
,
location
)
def
test_receive_google_callback
(
self
):
"""
Check if ERP5 set cookie properly after receive code from external service
"""
self
.
logout
()
response
=
self
.
portal
.
ERP5Site_receiveGoogleCallback
(
code
=
CODE
)
self
.
assertEqual
(
self
.
portal
.
absolute_url
(),
response
)
def
test_create_user_with_google_id
(
self
):
self
.
login
()
user_id
=
"go_"
+
getUserId
(
None
)
person
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
"Person"
,
reference
=
user_id
,
validation_state
=
"validated"
)
if
person
:
person
.
invalidate
()
self
.
tic
()
self
.
portal
.
Base_createOauth2User
(
'123_user_creation_in_progress'
,
'User'
,
'Last Name'
,
user_id
,
'example@email.com'
,
'Anonymous User'
)
self
.
tic
()
google_login
=
self
.
portal
.
portal_catalog
(
portal_type
=
"Google Login"
,
reference
=
user_id
,
validation_state
=
"validated"
)
self
.
assertNotEqual
(
None
,
google_login
)
self
.
login
(
user_id
)
person
=
self
.
portal
.
ERP5Site_getAuthenticatedMemberPersonValue
()
self
.
assertEqual
(
user_id
,
person
.
getReference
())
\ No newline at end of file
bt5/erp5_oauth_google_login/TestTemplateItem/portal_components/test.erp5.testGoogleLogin.xml
0 → 100644
View file @
b8d5d6c1
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"Test Component"
module=
"erp5.portal_type"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
_recorded_property_dict
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAI=
</string>
</persistent>
</value>
</item>
<item>
<key>
<string>
default_reference
</string>
</key>
<value>
<string>
testGoogleLogin
</string>
</value>
</item>
<item>
<key>
<string>
description
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
test.erp5.testGoogleLogin
</string>
</value>
</item>
<item>
<key>
<string>
portal_type
</string>
</key>
<value>
<string>
Test Component
</string>
</value>
</item>
<item>
<key>
<string>
sid
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
text_content_error_message
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
text_content_warning_message
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
version
</string>
</key>
<value>
<string>
erp5
</string>
</value>
</item>
<item>
<key>
<string>
workflow_history
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAM=
</string>
</persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record
id=
"2"
aka=
"AAAAAAAAAAI="
>
<pickle>
<global
name=
"PersistentMapping"
module=
"Persistence.mapping"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
data
</string>
</key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record
id=
"3"
aka=
"AAAAAAAAAAM="
>
<pickle>
<global
name=
"PersistentMapping"
module=
"Persistence.mapping"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
data
</string>
</key>
<value>
<dictionary>
<item>
<key>
<string>
component_validation_workflow
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAQ=
</string>
</persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record
id=
"4"
aka=
"AAAAAAAAAAQ="
>
<pickle>
<global
name=
"WorkflowHistoryList"
module=
"Products.ERP5Type.patches.WorkflowTool"
/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key>
<string>
action
</string>
</key>
<value>
<string>
validate
</string>
</value>
</item>
<item>
<key>
<string>
validation_state
</string>
</key>
<value>
<string>
validated
</string>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
bt5/erp5_oauth_google_login/bt/template_test_id_list
0 → 100644
View file @
b8d5d6c1
test.erp5.testGoogleLogin
\ No newline at end of file
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