Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
K
kedifa
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
kedifa
Commits
53e99f68
Commit
53e99f68
authored
Mar 28, 2019
by
Łukasz Nowak
Committed by
Łukasz Nowak
Apr 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updater: Cover updateCertificate
Fix one condition.
parent
2cd28eac
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
4 deletions
+77
-4
kedifa/test.py
kedifa/test.py
+74
-1
kedifa/updater.py
kedifa/updater.py
+2
-3
setup.py
setup.py
+1
-0
No files found.
kedifa/test.py
View file @
53e99f68
...
...
@@ -17,17 +17,18 @@
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
import
StringIO
import
contextlib
import
datetime
import
httplib
import
ipaddress
import
mock
import
multiprocessing
import
os
import
requests
import
requests.exceptions
import
shutil
import
signal
import
StringIO
import
sys
import
tempfile
import
time
...
...
@@ -1136,3 +1137,75 @@ class KedifaUpdaterMappingTest(KedifaMixin, unittest.TestCase):
u
=
Updater
(
1
,
self
.
mapping
,
None
,
None
,
None
,
None
,
True
)
u
.
updateMapping
()
self
.
assertEqual
(
u
.
mapping
,
{
'file'
:
'url'
})
class
KedifaUpdaterUpdateCertificateTest
(
KedifaMixin
,
unittest
.
TestCase
):
def
setupMapping
(
self
,
mapping_content
=
''
):
mapping
=
tempfile
.
NamedTemporaryFile
(
dir
=
self
.
testdir
,
delete
=
False
)
mapping
.
write
(
mapping_content
)
mapping
.
close
()
self
.
mapping
=
mapping
.
name
def
_update
(
self
,
certificate
,
fetch
,
master_content
):
certificate_file
=
tempfile
.
NamedTemporaryFile
(
dir
=
self
.
testdir
,
delete
=
False
)
certificate_file
.
write
(
certificate
)
certificate_file
.
close
()
self
.
setupMapping
(
'http://example.com %s'
%
(
certificate_file
.
name
,))
u
=
Updater
(
1
,
self
.
mapping
,
'/master/certificate/file'
,
None
,
None
,
None
,
True
)
u
.
updateMapping
()
with
mock
.
patch
.
object
(
Updater
,
'fetchCertificate'
,
return_value
=
fetch
):
result
=
u
.
updateCertificate
(
certificate_file
.
name
,
master_content
)
return
open
(
certificate_file
.
name
,
'r'
).
read
(),
result
def
test_nocert_nofetch_nomaster
(
self
):
certificate
,
update
=
self
.
_update
(
certificate
=
''
,
fetch
=
''
,
master_content
=
None
)
self
.
assertEqual
(
''
,
certificate
)
self
.
assertFalse
(
update
)
def
test_cert_nofetch_nomaster
(
self
):
certificate
,
update
=
self
.
_update
(
certificate
=
'old content'
,
fetch
=
''
,
master_content
=
None
)
self
.
assertEqual
(
'old content'
,
certificate
)
self
.
assertFalse
(
update
)
def
test_nocert_fetch_nomaster
(
self
):
certificate
,
update
=
self
.
_update
(
certificate
=
''
,
fetch
=
'content'
,
master_content
=
None
)
self
.
assertEqual
(
'content'
,
certificate
)
self
.
assertTrue
(
update
)
def
test_cert_fetch_nomaster
(
self
):
certificate
,
update
=
self
.
_update
(
certificate
=
'old content'
,
fetch
=
'content'
,
master_content
=
None
)
self
.
assertEqual
(
'content'
,
certificate
)
self
.
assertTrue
(
update
)
def
test_nocert_nofetch_master
(
self
):
certificate
,
update
=
self
.
_update
(
certificate
=
''
,
fetch
=
''
,
master_content
=
'master'
)
self
.
assertEqual
(
'master'
,
certificate
)
self
.
assertTrue
(
update
)
def
test_cert_nofetch_master
(
self
):
# This is important feature. Master certifcate does not override existing
# certificate, so it can use provided outside of KeDiFa
certificate
,
update
=
self
.
_update
(
certificate
=
'old content'
,
fetch
=
''
,
master_content
=
'master'
)
self
.
assertEqual
(
'old content'
,
certificate
)
self
.
assertFalse
(
update
)
def
test_nocert_fetch_master
(
self
):
certificate
,
update
=
self
.
_update
(
certificate
=
''
,
fetch
=
'content'
,
master_content
=
'master'
)
self
.
assertEqual
(
'content'
,
certificate
)
self
.
assertTrue
(
update
)
def
test_cert_fetch_master
(
self
):
certificate
,
update
=
self
.
_update
(
certificate
=
'old content'
,
fetch
=
'content'
,
master_content
=
'master'
)
self
.
assertEqual
(
'content'
,
certificate
)
self
.
assertTrue
(
update
)
kedifa/updater.py
View file @
53e99f68
...
...
@@ -60,13 +60,12 @@ class Updater(object):
except
IOError
:
current
=
''
if
not
(
certificate
)
and
not
current
:
if
master_content
is
not
None
:
if
not
(
certificate
):
if
not
current
and
master_content
is
not
None
:
url
=
self
.
master_certificate_file
certificate
=
master_content
else
:
return
False
if
current
!=
certificate
:
with
open
(
certificate_file
,
'w'
)
as
fh
:
fh
.
write
(
certificate
)
...
...
setup.py
View file @
53e99f68
...
...
@@ -23,6 +23,7 @@ import versioneer
tests_require
=
[
'urllib3 >= 1.18'
,
# https://github.com/urllib3/urllib3/issues/258
'ipaddress'
,
'mock'
,
]
setup
(
...
...
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