Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Debian New Member Process
contributors.debian.org
Commits
d06cf40c
Commit
d06cf40c
authored
Aug 02, 2017
by
Enrico Zini
Browse files
All tests pass
parent
c2ca1eb0
Changes
5
Hide whitespace changes
Inline
Side-by-side
contributors/housekeeping.py
View file @
d06cf40c
...
...
@@ -3,7 +3,7 @@ from django.conf import settings
from
contributors.models
import
User
,
Identifier
import
logging
import
os
import
ldap
import
ldap
3
import
json
import
six
from
.
import
models
as
cmodels
...
...
@@ -293,19 +293,25 @@ class UserAccountInfo(hk.Task):
# Get Debian usernames
if
LDAP_DEBIAN_URI
is
not
None
:
l
=
ldap
.
initialize
(
LDAP_DEBIAN_URI
)
for
dn
,
attrs
in
l
.
search_s
(
"dc=debian,dc=org"
,
ldap
.
SCOPE_SUBTREE
,
'(&(objectclass=inetOrgPerson)(gidNumber=800)(keyFingerPrint=*))'
,
[
b
"uid"
,
b
"gecos"
,
b
"emailForward"
,
b
"keyFingerPrint"
]):
userinfo
.
add_debian
(
dn
,
attrs
)
conn
=
ldap3
.
Connection
(
LDAP_DEBIAN_URI
,
auto_bind
=
True
)
conn
.
search
(
"dc=debian,dc=org"
,
'(&(objectclass=inetOrgPerson)(gidNumber=800)(keyFingerPrint=*))'
,
ldap3
.
SUBTREE
,
attributes
=
[
"uid"
,
"gecos"
,
"emailForward"
,
"keyFingerPrint"
])
for
entry
in
conn
.
entries
:
userinfo
.
add_debian
(
entry
.
entry_get_dn
(),
entry
)
# Get Alioth usernames
if
LDAP_ALIOTH_URI
is
not
None
:
l
=
ldap
.
initialize
(
LDAP_ALIOTH_URI
)
for
dn
,
attrs
in
l
.
search_s
(
"ou=Users,dc=alioth,dc=debian,dc=org"
,
ldap
.
SCOPE_SUBTREE
,
attrlist
=
[
b
"uid"
,
b
"cn"
,
b
"debGforgeForwardEmail"
]):
userinfo
.
add_alioth
(
dn
,
attrs
)
conn
=
ldap3
.
Connection
(
LDAP_ALIOTH_URI
,
auto_bind
=
True
)
conn
.
search
(
"ou=Users,dc=alioth,dc=debian,dc=org"
,
"(objectClass=*)"
,
ldap3
.
SUBTREE
,
attrlist
=
[
"uid"
,
"cn"
,
"debGforgeForwardEmail"
])
for
entry
in
conn
.
entries
:
userinfo
.
add_alioth
(
entry
.
entry_get_dn
(),
entry
)
log
.
info
(
"%d users loaded from Debian and Alioth's LDAP databases"
,
len
(
userinfo
.
by_uid
))
...
...
contributors/tests/test_permissions.py
View file @
d06cf40c
...
...
@@ -80,7 +80,7 @@ class ContributorsTestCase(SimpleSourceFixtureMixin, DCTestUtilsMixin, TestCase)
class
CannotPost
(
PostCheck
):
def
check_result
(
self
,
tc
):
tc
.
fixture
.
assertEqual
(
tc
.
response
.
status_code
,
403
)
data
=
json
.
loads
(
tc
.
response
.
content
)
data
=
tc
.
response
.
json
(
)
tc
.
fixture
.
assertEqual
(
data
[
"errors"
][
0
],
"Authentication token is not correct"
)
tc
.
fixture
.
assertEqual
(
data
[
"code"
],
403
)
tc
.
fixture
.
assertEqual
(
data
[
"records_parsed"
],
0
)
...
...
importer/importer.py
View file @
d06cf40c
...
...
@@ -2,6 +2,7 @@ from contributors import models
from
debiancontributors
import
parser
from
django
import
http
from
django.utils.timezone
import
now
import
io
import
json
import
logging
import
os.path
...
...
@@ -47,7 +48,7 @@ class Results(object):
}
def
to_response
(
self
):
response
=
http
.
HttpResponse
(
content_type
=
"
text/plai
n"
,
status
=
self
.
code
)
response
=
http
.
HttpResponse
(
content_type
=
"
application/jso
n"
,
status
=
self
.
code
)
json
.
dump
(
self
.
to_jsonable
(),
response
,
indent
=
2
)
return
response
...
...
@@ -167,8 +168,10 @@ class Importer(object):
"""
Uncompress and json-decode the submission data from a POST request
"""
from
django.core.files.uploadhandler
import
TemporaryFileUploadHandler
,
InMemoryUploadedFile
# Validate the data
data
=
request
.
FILES
.
get
(
"data"
,
None
)
data
=
request
.
FILES
.
get
(
"data"
)
if
data
is
None
:
raise
parser
.
Fail
(
400
,
"no file was posted in a 'data' field"
)
...
...
@@ -178,7 +181,12 @@ class Importer(object):
compression
=
parser
.
get_key_string
(
request
.
POST
,
"data_compression"
,
guess
)
# Decode the data
parsed
=
parser
.
get_json
(
data
,
compression
)
if
isinstance
(
data
,
InMemoryUploadedFile
):
parsed
=
parser
.
get_json
(
io
.
BytesIO
(
data
.
read
()),
compression
)
else
:
with
open
(
data
.
temporary_file_path
(),
"rb"
)
as
fd
:
parsed
=
parser
.
get_json
(
fd
,
compression
)
return
parsed
def
import_request
(
self
,
request
):
...
...
importer/tests.py
View file @
d06cf40c
from
django.test
import
TestCase
#
from django.
util
s import
unittest
from
django.test
import
TestCase
,
RequestFactory
from
django.
core.urlresolver
s
import
reverse
from
contributors
import
models
as
bmodels
from
.
import
importer
from
io
import
String
IO
from
io
import
Bytes
IO
import
datetime
import
json
class
FakeRequest
(
object
):
def
__init__
(
self
):
self
.
POST
=
{}
self
.
FILES
=
{}
self
.
META
=
{}
class
ImportTest
(
TestCase
):
def
setUp
(
self
):
self
.
source
=
bmodels
.
Source
(
name
=
"test"
,
auth_token
=
"foo"
)
...
...
@@ -51,12 +45,14 @@ class ImportTest(TestCase):
}
def
make_request
(
self
,
data
):
res
=
FakeRequest
()
res
.
method
=
"POST"
res
.
POST
[
"source"
]
=
self
.
source
.
name
res
.
POST
[
"auth_token"
]
=
self
.
source
.
auth_token
res
.
FILES
[
"data"
]
=
StringIO
(
json
.
dumps
(
data
))
return
res
factory
=
RequestFactory
()
submission
=
BytesIO
(
json
.
dumps
(
data
).
encode
(
"utf-8"
))
submission
.
name
=
"submission.json"
return
factory
.
post
(
reverse
(
"contributors_post"
),
data
=
{
"source"
:
self
.
source
.
name
,
"auth_token"
:
self
.
source
.
auth_token
,
"data"
:
submission
,
})
def
test_simple_import
(
self
):
"""
...
...
importer/views.py
View file @
d06cf40c
...
...
@@ -8,7 +8,7 @@ from .importer import Importer
import
contributors.models
as
cmodels
import
json
class
CSRFExemptMixin
(
View
)
:
class
CSRFExemptMixin
:
@
method_decorator
(
csrf_exempt
)
def
dispatch
(
self
,
*
args
,
**
kwargs
):
return
super
(
CSRFExemptMixin
,
self
).
dispatch
(
*
args
,
**
kwargs
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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