Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"test": {
'symlinks': {
join(str(tmpdir), "link"): {
'target': join(str(tmpdir), "dir2"),
},
},
},
},
nodes={
"localhost": {
'bundles': ["test"],
'os': host_os(),
},
},
)
stdout, stderr, rcode = run("bw apply localhost", path=str(tmpdir))
assert rcode == 0
assert readlink(join(str(tmpdir), "link")) == join(str(tmpdir), "dir2")
},
join(str(tmpdir), "baz"): {
'content_type': 'any',
},
},
},
},
nodes={
"localhost": {
'bundles': ["test", "test2"],
'os': host_os(),
},
},
)
run("bw apply -o bundle:test localhost", path=str(tmpdir))
assert exists(join(str(tmpdir), "foo"))
assert exists(join(str(tmpdir), "bar"))
assert not exists(join(str(tmpdir), "baz"))
"files": {
"/tmp/test": {
'content': "one",
},
},
},
"bundle2": {
"files": {
"/tmp/test": {
'content': "two",
},
},
},
},
)
stdout, stderr, rcode = run("bw diff -i file:/tmp/test -- node1 node2", path=str(tmpdir))
assert b"one" in stdout
assert b"two" in stdout
assert stderr == b""
assert rcode == 0
'bundles': ["test"],
},
},
)
with open(join(str(tmpdir), "bundles", "test", "metadata.py"), 'w') as f:
f.write(
"""
@metadata_reactor
def plusone(metadata):
return {'foo': metadata.get('bar', 0) + 1 }
@metadata_reactor
def plustwo(metadata):
return {'bar': metadata.get('foo', 0) + 2 }
""")
stdout, stderr, rcode = run("bw metadata node1", path=str(tmpdir))
assert rcode == 1
"files": {
"/tmp/foo": {
'content': "two",
},
},
},
"bundle3": {
"files": {
"/tmp/bar": {
'content': "common",
},
},
},
},
)
stdout, stderr, rcode = run("bw diff node1 node2", path=str(tmpdir))
assert b"/tmp/foo" in stdout
assert b"/tmp/bar" not in stdout
assert stderr == b""
assert rcode == 0
def test_encrypt(tmpdir):
make_repo(tmpdir)
stdout, stderr, rcode = run("bw debug -c 'print(repo.vault.encrypt(\"test\"))'", path=str(tmpdir))
assert stderr == b""
assert rcode == 0
stdout, stderr, rcode = run("bw debug -c 'print(repo.vault.decrypt(\"{}\"))'".format(stdout.decode('utf-8').strip()), path=str(tmpdir))
assert stdout == b"test\n"
assert stderr == b""
assert rcode == 0
def test_encrypt(tmpdir):
make_repo(tmpdir)
stdout, stderr, rcode = run("bw debug -c 'print(repo.vault.encrypt(\"test\"))'", path=str(tmpdir))
assert stderr == b""
assert rcode == 0
stdout, stderr, rcode = run("bw debug -c 'print(repo.vault.decrypt(\"{}\"))'".format(stdout.decode('utf-8').strip()), path=str(tmpdir))
assert stdout == b"test\n"
assert stderr == b""
assert rcode == 0
'files': {
join(str(tmpdir), "foo.bin"): {
'content_type': 'base64',
'content': b64encode("ö".encode('latin-1')),
},
},
},
},
nodes={
"localhost": {
'bundles': ["test"],
'os': host_os(),
},
},
)
run("bw apply localhost", path=str(tmpdir))
with open(join(str(tmpdir), "foo.bin"), 'rb') as f:
content = f.read()
assert content.decode('latin-1') == "ö"
def test_template_node_cascade(tmpdir):
make_repo(
tmpdir,
nodes={
"node1": {'template_node': "node2"},
"node2": {'template_node': "node1"},
},
)
stdout, stderr, rcode = run("BW_TABLE_STYLE=grep bw nodes node1 dummy", path=str(tmpdir))
assert rcode == 1
def test_human_password(tmpdir):
make_repo(tmpdir)
stdout, stderr, rcode = run("bw debug -c 'print(repo.vault.human_password_for(\"hello world\"))'", path=str(tmpdir))
assert stdout == b"Xaint-Heep-Pier-Tikl-76\n"
assert stderr == b""
assert rcode == 0