test_add_stunnel_ca_options.py 1.09 KB
Newer Older
Max Beckett's avatar
Max Beckett committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
# Copyright 2017-2018 Amazon.com, Inc. and its affiliates. All Rights Reserved.
#
# Licensed under the MIT License. See the LICENSE accompanying this file
# for the specific language governing permissions and limitations under
# the License.
#

import mount_efs
import tempfile

import pytest

CAPATH = '/capath'
CAFILE = '/cafile.crt'


def create_temp_file(tmpdir, content=''):
    temp_file = tmpdir.join(tempfile.mktemp())
    temp_file.write(content, ensure=True)
    return temp_file


Ian Patel's avatar
Ian Patel committed
24
def test_use_existing_cafile(tmpdir):
Max Beckett's avatar
Max Beckett committed
25
    efs_config = {}
Ian Patel's avatar
Ian Patel committed
26
    stunnel_cafile = str(create_temp_file(tmpdir))
Max Beckett's avatar
Max Beckett committed
27

Ian Patel's avatar
Ian Patel committed
28
    mount_efs.add_stunnel_ca_options(efs_config, stunnel_cafile)
Max Beckett's avatar
Max Beckett committed
29

Ian Patel's avatar
Ian Patel committed
30
    assert stunnel_cafile == efs_config.get('CAfile')
Max Beckett's avatar
Max Beckett committed
31
32
33
    assert 'CApath' not in efs_config


Ian Patel's avatar
Ian Patel committed
34
def test_use_missing_cafile(capsys):
Max Beckett's avatar
Max Beckett committed
35
    efs_config = {}
Ian Patel's avatar
Ian Patel committed
36
    stunnel_cafile = '/missing1'
Max Beckett's avatar
Max Beckett committed
37
38

    with pytest.raises(SystemExit) as ex:
Ian Patel's avatar
Ian Patel committed
39
        mount_efs.add_stunnel_ca_options(efs_config, stunnel_cafile)
Max Beckett's avatar
Max Beckett committed
40
41
42
43

    assert 0 != ex.value.code

    out, err = capsys.readouterr()
Ian Patel's avatar
Ian Patel committed
44
    assert 'Failed to find the EFS certificate authority file for verification' in err