Esempio n. 1
0
def test_is_bootstrapping_stat_file(tmpdir):
    agent.CERT_PATH = str(tmpdir)
    agent.CLIENT_CERT_PATH = str(tmpdir / 'client.crt')
    with mock.patch('agent.logger') as prn:
        assert agent.is_bootstrapping()
        assert mock.call(
            'No certificate found on disk.') in prn.warning.mock_calls
Esempio n. 2
0
def test_is_bootstrapping_false_on_valid_cert(tmpdir):
    crt = tmpdir / 'client.crt'
    agent.CERT_PATH = str(tmpdir)
    agent.CLIENT_CERT_PATH = str(crt)
    with mock.patch('builtins.print') as prn:
        Path(crt).write_text('nonzero')
        assert not agent.is_bootstrapping()
        assert not prn.mock_calls
Esempio n. 3
0
def test_is_bootstrapping_check_filesize(tmpdir):
    crt = tmpdir / 'client.crt'
    agent.CERT_PATH = str(tmpdir)
    agent.CLIENT_CERT_PATH = str(crt)
    with mock.patch('agent.logger') as prn:
        Path(agent.CLIENT_CERT_PATH).touch()
        assert agent.is_bootstrapping()
        assert mock.call('Certificate found but it is broken') in prn.warning.mock_calls
Esempio n. 4
0
def test_is_bootstrapping_create_dir(tmpdir):
    notexistent_dir = str(tmpdir / 'notexistent')
    agent.CERT_PATH = notexistent_dir
    with mock.patch('os.makedirs') as md, \
            mock.patch('os.chmod') as chm, \
            mock.patch('builtins.print') as prn:
        assert agent.is_bootstrapping()
        assert md.called_with(notexistent_dir)
        assert chm.called_with(notexistent_dir, 0o700)
        assert mock.call('No certificate found on disk.') in prn.mock_calls
Esempio n. 5
0
def test_is_bootstrapping_create_dir(tmpdir):
    notexistent_dir = tmpdir / 'notexistent'
    agent.CERT_PATH = str(notexistent_dir)
    agent.CLIENT_CERT_PATH = str(notexistent_dir / 'client.crt')
    with mock.patch('os.makedirs') as md, \
            mock.patch('os.chmod') as chm, \
            mock.patch('agent.logger') as prn:
        assert agent.is_bootstrapping()
        assert md.called_with(notexistent_dir)
        assert chm.called_with(notexistent_dir, 0o700)
        assert mock.call('No certificate found on disk.') in prn.warning.mock_calls
Esempio n. 6
0
def test_is_bootstrapping_stat_file(tmpdir):
    agent.CERT_PATH = str(tmpdir)
    with mock.patch('builtins.print') as prn:
        assert agent.is_bootstrapping()
        assert mock.call('No certificate found on disk.') in prn.mock_calls