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
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
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Ramos Carreño
erp5
Commits
e7e0fe37
Commit
e7e0fe37
authored
Aug 26, 2019
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_certificate_authority: Implement backward-compatibility with ERP5 Login
Also extend tests to cover recently changes
parent
7bf38f10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
3 deletions
+112
-3
bt5/erp5_certificate_authority/DocumentTemplateItem/portal_components/document.erp5_certificate_authority.Person.py
..._components/document.erp5_certificate_authority.Person.py
+10
-1
bt5/erp5_certificate_authority/TestTemplateItem/portal_components/test.erp5_certificate_authority.testCertificateAuthorityTool.py
...rp5_certificate_authority.testCertificateAuthorityTool.py
+102
-2
No files found.
bt5/erp5_certificate_authority/DocumentTemplateItem/portal_components/document.erp5_certificate_authority.Person.py
View file @
e7e0fe37
...
...
@@ -7,7 +7,16 @@ class Person(ERP5Person):
security
.
declarePublic
(
'getCertificate'
)
def
_getCertificateLoginDocument
(
self
):
for
_certificate_login
in
self
.
objectValues
(
portal_type
=
"Certificate Login"
):
for
_erp5_login
in
self
.
objectValues
(
portal_type
=
[
"ERP5 Login"
]):
if
_erp5_login
.
getValidationState
()
==
"validated"
and
\
_erp5_login
.
getReference
()
==
self
.
getUserId
():
# The user already created a Login document as UserId, so
# So just use this one.
return
_erp5_login
for
_certificate_login
in
self
.
objectValues
(
portal_type
=
[
"Certificate Login"
]):
if
_certificate_login
.
getValidationState
()
==
"validated"
:
return
_certificate_login
...
...
bt5/erp5_certificate_authority/TestTemplateItem/portal_components/test.erp5_certificate_authority.testCertificateAuthorityTool.py
View file @
e7e0fe37
...
...
@@ -31,6 +31,7 @@ import os
import
random
import
unittest
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.DCWorkflow.DCWorkflow
import
ValidationFailed
from
AccessControl
import
Unauthorized
class
TestCertificateAuthority
(
ERP5TypeTestCase
):
...
...
@@ -39,8 +40,9 @@ class TestCertificateAuthority(ERP5TypeTestCase):
return
"Test Certificate Authority"
def
afterSetUp
(
self
):
self
.
portal
.
portal_certificate_authority
.
certificate_authority_path
=
\
os
.
environ
[
'TEST_CA_PATH'
]
if
"TEST_CA_PATH"
in
os
.
environ
:
self
.
portal
.
portal_certificate_authority
.
certificate_authority_path
=
\
os
.
environ
[
'TEST_CA_PATH'
]
def
getBusinessTemplateList
(
self
):
return
(
'erp5_base'
,
'erp5_certificate_authority'
)
...
...
@@ -59,6 +61,30 @@ class TestCertificateAuthority(ERP5TypeTestCase):
self
.
loginByUserName
(
login
)
person
=
self
.
portal
.
portal_membership
.
getAuthenticatedMember
().
getUserValue
()
certificate
=
person
.
getCertificate
()
certificate_login_list
=
person
.
objectValues
(
portal_type
=
"Certificate Login"
)
self
.
assertEquals
(
len
(
certificate_login_list
),
1
)
certificate_login
=
certificate_login_list
[
0
]
self
.
assertEquals
(
certificate_login
.
getReference
(),
user_id
)
self
.
assertEquals
(
certificate_login
.
getValidationState
(),
"validated"
)
self
.
assertTrue
(
'CN=%s'
%
user_id
in
certificate
[
'certificate'
])
def
test_person_duplicated_login
(
self
):
user_id
,
login
=
self
.
_createPerson
()
self
.
loginByUserName
(
login
)
person
=
self
.
portal
.
portal_membership
.
getAuthenticatedMember
().
getUserValue
()
person
.
newContent
(
portal_type
=
'ERP5 Login'
,
reference
=
user_id
).
validate
()
self
.
tic
()
certificate
=
person
.
getCertificate
()
certificate_login_list
=
person
.
objectValues
(
portal_type
=
"Certificate Login"
)
# If a erp5_login is already using the User ID, just reuse it for now
self
.
assertEquals
(
len
(
certificate_login_list
),
0
)
self
.
assertTrue
(
'CN=%s'
%
user_id
in
certificate
[
'certificate'
])
def
test_person_revoke_certificate
(
self
):
...
...
@@ -72,6 +98,14 @@ class TestCertificateAuthority(ERP5TypeTestCase):
self
.
loginByUserName
(
login
)
person
=
self
.
portal
.
portal_membership
.
getAuthenticatedMember
().
getUserValue
()
certificate
=
person
.
getCertificate
()
certificate_login_list
=
person
.
objectValues
(
portal_type
=
"Certificate Login"
)
self
.
assertEquals
(
len
(
certificate_login_list
),
1
)
certificate_login
=
certificate_login_list
[
0
]
self
.
assertEquals
(
certificate_login
.
getReference
(),
user_id
)
self
.
assertEquals
(
certificate_login
.
getValidationState
(),
"validated"
)
self
.
assertTrue
(
'CN=%s'
%
user_id
in
certificate
[
'certificate'
])
person
.
revokeCertificate
()
...
...
@@ -80,9 +114,56 @@ class TestCertificateAuthority(ERP5TypeTestCase):
self
.
loginByUserName
(
login
)
person
=
self
.
portal
.
portal_membership
.
getAuthenticatedMember
().
getUserValue
()
certificate
=
person
.
getCertificate
()
certificate_login_list
=
person
.
objectValues
(
portal_type
=
"Certificate Login"
)
self
.
assertEquals
(
len
(
certificate_login_list
),
1
)
certificate_login
=
certificate_login_list
[
0
]
self
.
assertEquals
(
certificate_login
.
getReference
(),
user_id
)
self
.
assertTrue
(
'CN=%s'
%
user_id
in
certificate
[
'certificate'
])
self
.
assertEquals
(
certificate_login
.
getValidationState
(),
"validated"
)
self
.
assertRaises
(
ValueError
,
person
.
getCertificate
)
# Ensure it don't create a second object
certificate_login_list
=
person
.
objectValues
(
portal_type
=
"Certificate Login"
)
self
.
assertEquals
(
len
(
certificate_login_list
),
1
)
certificate_login
=
certificate_login_list
[
0
]
self
.
assertEquals
(
certificate_login
.
getReference
(),
user_id
)
self
.
assertEquals
(
certificate_login
.
getValidationState
(),
"validated"
)
def
test_person_request_revoke_request_certificate
(
self
):
user_id
,
login
=
self
.
_createPerson
()
self
.
loginByUserName
(
login
)
person
=
self
.
portal
.
portal_membership
.
getAuthenticatedMember
().
getUserValue
()
certificate
=
person
.
getCertificate
()
certificate_login_list
=
person
.
objectValues
(
portal_type
=
"Certificate Login"
)
self
.
assertEquals
(
len
(
certificate_login_list
),
1
)
certificate_login
=
certificate_login_list
[
0
]
self
.
assertEquals
(
certificate_login
.
getReference
(),
user_id
)
self
.
assertTrue
(
'CN=%s'
%
user_id
in
certificate
[
'certificate'
])
self
.
assertEquals
(
certificate_login
.
getValidationState
(),
"validated"
)
person
.
revokeCertificate
()
certificate
=
person
.
getCertificate
()
# Ensure it don't create a second object
certificate_login_list
=
person
.
objectValues
(
portal_type
=
"Certificate Login"
)
self
.
assertEquals
(
len
(
certificate_login_list
),
1
)
certificate_login
=
certificate_login_list
[
0
]
self
.
assertEquals
(
certificate_login
.
getReference
(),
user_id
)
self
.
assertEquals
(
certificate_login
.
getValidationState
(),
"validated"
)
def
test_person_request_certificate_for_another
(
self
):
_
,
login
=
self
.
_createPerson
()
_
,
login2
=
self
.
_createPerson
()
...
...
@@ -91,6 +172,25 @@ class TestCertificateAuthority(ERP5TypeTestCase):
self
.
loginByUserName
(
login2
)
self
.
assertRaises
(
Unauthorized
,
person
.
getCertificate
)
def
test_person_duplicated_login_from_another_user
(
self
):
user_id
,
login
=
self
.
_createPerson
()
person
=
self
.
portal
.
person_module
.
newContent
(
portal_type
=
'Person'
,
reference
=
str
(
random
.
random
()),
password
=
login
)
person
.
newContent
(
portal_type
=
'Assignment'
).
open
()
# Try to create a login with other person user_id to cheat the system
person
.
newContent
(
portal_type
=
'ERP5 Login'
,
reference
=
user_id
).
validate
()
self
.
tic
()
self
.
loginByUserName
(
login
)
person
=
self
.
portal
.
portal_membership
.
getAuthenticatedMember
().
getUserValue
()
self
.
assertRaises
(
ValidationFailed
,
person
.
getCertificate
)
certificate_login_list
=
[
i
for
i
in
person
.
objectValues
(
portal_type
=
"Certificate Login"
)
if
i
.
getValidationState
()
==
"validated"
]
self
.
assertEquals
(
len
(
certificate_login_list
),
0
)
def
test_person_revoke_certificate_for_another
(
self
):
user_id
,
login
=
self
.
_createPerson
()
_
,
login2
=
self
.
_createPerson
()
...
...
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