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
mentors.debian.net
debexpo
Commits
c94cc0f4
Verified
Commit
c94cc0f4
authored
Oct 17, 2021
by
Baptiste Beauplat
Browse files
Add tests for HKP implementation
parent
035a92ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/functional/keyring/test_hkp.py
0 → 100644
View file @
c94cc0f4
# test_hkp.py - Test HKP implementation
#
# This file is part of debexpo
# https://salsa.debian.org/mentors.debian.net-team/debexpo
#
# Copyright © 2021 Baptiste Beauplat <lyknode@cilg.org>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
from
django.test
import
LiveServerTestCase
from
debexpo.tools.gnupg
import
GnuPG
from
tests
import
TransactionTestController
class
TestHKP
(
TransactionTestController
,
LiveServerTestCase
):
def
setUp
(
self
):
self
.
_setup_example_user
(
gpg
=
True
)
def
test_gpg_recv_keys
(
self
):
gpg
=
GnuPG
()
# On existing key
(
output
,
status
)
=
gpg
.
_run
(
args
=
[
'--keyserver'
,
'hkp://'
+
self
.
live_server_url
.
split
(
'/'
)[
2
],
'--recv-keys'
,
'0x'
+
self
.
_GPG_FINGERPRINT
[
-
16
:]])
self
.
assertIn
(
'IMPORT_OK 1'
,
output
)
self
.
assertEquals
(
0
,
status
)
# On non-existing key
(
output
,
status
)
=
gpg
.
_run
(
args
=
[
'--keyserver'
,
'hkp://'
+
self
.
live_server_url
.
split
(
'/'
)[
2
],
'--recv-keys'
,
'0xCA11AB1E'
])
self
.
assertIn
(
'FAILURE recv-keys'
,
output
)
self
.
assertEquals
(
2
,
status
)
tests/unit/keyring/test_hkp.py
0 → 100644
View file @
c94cc0f4
# test_hkp.py - Test HKP implementation
#
# This file is part of debexpo
# https://salsa.debian.org/mentors.debian.net-team/debexpo
#
# Copyright © 2021 Baptiste Beauplat <lyknode@cilg.org>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
from
django.urls
import
reverse
from
tests
import
TestController
_GPGKEY
=
"""-----BEGIN PGP PUBLIC KEY BLOCK-----
mDMEW9b91RYJKwYBBAHaRw8BAQdAHtUIQWAsmPilu0JDMnLbpPQfT1i3z2IVMoDH
rhlYkO+0JWRlYmV4cG8gdGVzdGluZyA8ZGViZXhwb0BleGFtcGxlLm9yZz6IkAQT
FggAOBYhBOF57qTrR+YF2YZjLihiGOfHT5wRBQJb1v3VAhsDBQsJCAcCBhUKCQgL
AgQWAgMBAh4BAheAAAoJEChiGOfHT5wRdQIBAJ8rciR0e1PaA+LhoTWHaPSgCwvc
lNFyRk71s75+hRkhAPwPnl6QqGsOa0DyJB5saVcqPCqYFbF1usUWIQnPPRsVC7g4
BFvW/dUSCisGAQQBl1UBBQEBB0DzrYDCp+OaNFinqKkDWcqftqq/BAFS9lq4de5g
RNytNAMBCAeIeAQYFggAIBYhBOF57qTrR+YF2YZjLihiGOfHT5wRBQJb1v3VAhsM
AAoJEChiGOfHT5wRNK8A/115pc8+OwKDy1fGXGX3l0uq1wdfiJreG/9YZddx/JTI
AQD4ZLpyUg+z6kJ+8YAmHFiOD9Ixv3QVvrfpBwnBVtJZBg==
=N+9W
-----END PGP PUBLIC KEY BLOCK-----"""
class
TestHKP
(
TestController
):
def
setUp
(
self
):
self
.
_setup_example_user
(
gpg
=
True
)
another
=
self
.
_setup_example_user
(
email
=
'another@example.org'
)
self
.
_add_gpg_key
(
another
,
_GPGKEY
,
'FINGERPRINT'
,
'22'
,
256
)
def
test_op
(
self
):
# Missing op parameter: 400
response
=
self
.
client
.
get
(
reverse
(
'hkp'
))
self
.
assertEquals
(
response
.
status_code
,
400
)
self
.
assertIn
(
"Missing 'op'"
,
str
(
response
.
content
))
# Unknown op: 501
response
=
self
.
client
.
get
(
reverse
(
'hkp'
),
{
'op'
:
'not-implemented'
})
self
.
assertEquals
(
response
.
status_code
,
501
)
self
.
assertIn
(
"Not Implemented"
,
str
(
response
.
content
))
def
test_get
(
self
):
# Missing search parameter: 400
response
=
self
.
client
.
get
(
reverse
(
'hkp'
),
{
'op'
:
'get'
})
self
.
assertEquals
(
response
.
status_code
,
400
)
self
.
assertIn
(
"Missing 'search'"
,
str
(
response
.
content
))
# No match: 404
response
=
self
.
client
.
get
(
reverse
(
'hkp'
),
{
'op'
:
'get'
,
'search'
:
'not-found'
})
self
.
assertEquals
(
response
.
status_code
,
404
)
self
.
assertIn
(
'Not Found'
,
str
(
response
.
content
))
# Multiple matches: 500
response
=
self
.
client
.
get
(
reverse
(
'hkp'
),
{
'op'
:
'get'
,
'search'
:
''
})
self
.
assertEquals
(
response
.
status_code
,
500
)
self
.
assertIn
(
"Multiple matches found"
,
str
(
response
.
content
))
# Matches long id: 200
response
=
self
.
client
.
get
(
reverse
(
'hkp'
),
{
'op'
:
'get'
,
'search'
:
'0x'
+
self
.
_GPG_FINGERPRINT
[
-
16
:]
})
self
.
assertEquals
(
response
.
status_code
,
200
)
self
.
assertIn
(
self
.
_GPG_KEY
,
response
.
content
.
decode
())
# Matches full fingerprint: 200
response
=
self
.
client
.
get
(
reverse
(
'hkp'
),
{
'op'
:
'get'
,
'search'
:
self
.
_GPG_FINGERPRINT
})
self
.
assertEquals
(
response
.
status_code
,
200
)
self
.
assertIn
(
self
.
_GPG_KEY
,
response
.
content
.
decode
())
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