Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33103555
helpers_test.py
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
helpers_test.py
View Options
import
unittest
import
json
from
lilybuild.helpers
import
rsync_rules_from_artifacts
,
normalize_base_url
,
phorge_token_to_arcrc
,
ci_vars_to_cmds
class
RsyncRulesTest
(
unittest
.
TestCase
):
def
test_empty
(
self
):
self
.
assertEqual
(
rsync_rules_from_artifacts
({}),
[
'--include'
,
'*/'
,
'--exclude'
,
'*'
]
)
def
test_simple
(
self
):
self
.
assertEqual
(
rsync_rules_from_artifacts
({
'paths'
:
[
'public'
]}),
[
'--include'
,
'*/'
,
'--include'
,
'/public'
,
'--include'
,
'/public/**'
,
'--exclude'
,
'*'
]
)
def
test_dotslash
(
self
):
self
.
assertEqual
(
rsync_rules_from_artifacts
({
'paths'
:
[
'./public/'
]}),
[
'--include'
,
'*/'
,
'--include'
,
'/public'
,
'--include'
,
'/public/**'
,
'--exclude'
,
'*'
]
)
def
test_doublestar
(
self
):
self
.
assertEqual
(
rsync_rules_from_artifacts
({
'paths'
:
[
'./public/**'
]}),
[
'--include'
,
'*/'
,
'--include'
,
'/public/**'
,
'--include'
,
'/public/**/**'
,
'--exclude'
,
'*'
]
)
def
test_doublestar_middle
(
self
):
self
.
assertEqual
(
rsync_rules_from_artifacts
({
'paths'
:
[
'./public/**/*.html'
]}),
[
'--include'
,
'*/'
,
'--include'
,
'/public/**/*.html'
,
'--include'
,
'/public/**/*.html/**'
,
'--exclude'
,
'*'
]
)
def
test_dotdotslash
(
self
):
# No exploit possible because rsync will not visit beyond the source root
self
.
assertEqual
(
rsync_rules_from_artifacts
({
'paths'
:
[
'../etc/passwd'
]}),
[
'--include'
,
'*/'
,
'--include'
,
'/../etc/passwd'
,
'--include'
,
'/../etc/passwd/**'
,
'--exclude'
,
'*'
]
)
class
PhorgeUtilsTest
(
unittest
.
TestCase
):
def
test_normalize_base_url
(
self
):
self
.
assertEqual
(
normalize_base_url
(
'https://iron.lily-is.land/'
),
'https://iron.lily-is.land'
)
self
.
assertEqual
(
normalize_base_url
(
'https://iron.lily-is.land'
),
'https://iron.lily-is.land'
)
self
.
assertEqual
(
normalize_base_url
(
''
),
None
)
def
test_phorge_token_to_arcrc
(
self
):
self
.
assertEqual
(
json
.
loads
(
phorge_token_to_arcrc
(
'https://iron.lily-is.land'
,
'some-token'
)),
{
'hosts'
:
{
'https://iron.lily-is.land/api/'
:
{
'token'
:
'some-token'
,
},
},
},
)
class
CiVarsTest
(
unittest
.
TestCase
):
def
test_simple
(
self
):
self
.
assertEqual
(
ci_vars_to_cmds
({}),
''
)
self
.
assertEqual
(
ci_vars_to_cmds
({
'VAR'
:
'val'
}),
'export VAR=val'
)
self
.
assertEqual
(
ci_vars_to_cmds
({
'VAR'
:
'foo bar'
}),
"export VAR='foo bar'"
)
if
__name__
==
'__main__'
:
unittest
.
main
()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 20, 1:58 PM (10 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
973798
Default Alt Text
helpers_test.py (2 KB)
Attached To
Mode
rB lilybuild
Attached
Detach File
Event Timeline
Log In to Comment