1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#!/usr/bin/env python3
'''
t4_authinfo.py - this file is part of S3QL.
Copyright © 2019 Nikolaus Rath <Nikolaus@rath.org>
This work can be distributed under the terms of the GNU GPLv3.
'''
if __name__ == '__main__':
import sys
import pytest
sys.exit(pytest.main([__file__] + sys.argv[1:]))
import shutil
import subprocess
import tempfile
from argparse import Namespace
import pytest
def test_invalid_option(s3ql_cmd_argv, reg_output):
with tempfile.NamedTemporaryFile('wt') as fh:
print('[entry1]', 'storage-url: local:///foo', 'invalid-option: bla', '', file=fh, sep='\n')
fh.flush()
proc = subprocess.Popen(
s3ql_cmd_argv('fsck.s3ql')
+ ['--quiet', '--authfile', fh.name, '--log', 'none', 'local:///foo/bar'],
stdin=subprocess.PIPE,
universal_newlines=True,
)
proc.stdin.close()
assert proc.wait() == 2
reg_output(r"ERROR: '/com' does not exist", count=1)
proc = subprocess.Popen(
s3ql_cmd_argv('fsck.s3ql')
+ ['--quiet', '--authfile', fh.name, '--log', 'none', 'local:///com'],
stdin=subprocess.PIPE,
universal_newlines=True,
)
proc.stdin.close()
assert proc.wait() == 16
def test_invalid_backend_option(s3ql_cmd_argv):
with tempfile.NamedTemporaryFile('wt') as fh:
print(
'[entry1]',
'storage-url: local:///foo',
'backend-options: invalid-key',
file=fh,
sep='\n',
)
fh.flush()
proc = subprocess.Popen(
s3ql_cmd_argv('fsck.s3ql')
+ ['--quiet', '--authfile', fh.name, '--log', 'none', 'local:///foo/bar'],
stdin=subprocess.PIPE,
universal_newlines=True,
)
proc.stdin.close()
assert proc.wait() == 3
def test_option_precedence(s3ql_cmd_argv, reg_output):
with tempfile.NamedTemporaryFile('wt') as fh:
print(
'[entry1]',
'storage-url: s3://',
'backend-options: invalid-key',
'',
'[entry2]',
'storage-url: s3://foo',
'backend-options: no-ssl',
file=fh,
sep='\n',
)
fh.flush()
reg_output(r"ERROR: Invalid storage URL", count=1)
proc = subprocess.Popen(
s3ql_cmd_argv('fsck.s3ql')
+ ['--quiet', '--authfile', fh.name, '--log', 'none', 's3://foo'],
stdin=subprocess.PIPE,
universal_newlines=True,
)
proc.stdin.close()
assert proc.wait() == 2
@pytest.fixture()
def context():
ctx = Namespace()
ctx.cache_dir = tempfile.mkdtemp(prefix='s3ql-cache-')
ctx.backend_dir = tempfile.mkdtemp(prefix='s3ql-backend-')
ctx.storage_url = 'local://' + ctx.backend_dir
yield ctx
shutil.rmtree(ctx.cache_dir)
shutil.rmtree(ctx.backend_dir)
def test_passphrase(context, reg_output, s3ql_cmd_argv):
passphrase = 'out3d'
proc = subprocess.Popen(
s3ql_cmd_argv('mkfs.s3ql')
+ [
'-L',
'test fs',
'--data-block-size',
'500',
'--authfile',
'/dev/null',
'--cachedir',
context.cache_dir,
'--quiet',
context.storage_url,
],
stdin=subprocess.PIPE,
universal_newlines=True,
)
print(passphrase, file=proc.stdin)
print(passphrase, file=proc.stdin)
proc.stdin.close()
assert proc.wait() == 0
with tempfile.NamedTemporaryFile('wt') as fh:
print(
'[entry1]',
'storage-url: local://',
'fs-passphrase: clearly wrong',
'',
'[entry2]',
'storage-url: %s' % context.storage_url,
'fs-passphrase: %s' % passphrase,
file=fh,
sep='\n',
)
fh.flush()
proc = subprocess.Popen(
s3ql_cmd_argv('fsck.s3ql')
+ [
'--quiet',
'--authfile',
fh.name,
'--cachedir',
context.cache_dir,
'--log',
'none',
context.storage_url,
],
stdin=subprocess.PIPE,
universal_newlines=True,
)
proc.stdin.close()
assert proc.wait() == 0
|