Exemple #1
0
def test_set_acme_record():
    strato = CertbotStratoApi()

    strato.set_amce_record()

    assert len(strato.records) == 1
    assert strato.records[0]['prefix'] == '_acme-challenge'
    assert strato.records[0]['type'] == 'TXT'
    assert strato.records[0]['value'] == 'xyz'
Exemple #2
0
def test_add_record():
    strato = CertbotStratoApi()

    strato.add_txt_record('subdomain', 'TXT', 'myvalue')

    assert len(strato.records) == 1
    assert strato.records[0]['prefix'] == 'subdomain'
    assert strato.records[0]['type'] == 'TXT'
    assert strato.records[0]['value'] == 'myvalue'
Exemple #3
0
def test_get_package_id(test_input, expected, requests_mock):
    project_page = open('test/projectPage.html', 'r').read()
    os.environ['CERTBOT_DOMAIN'] = test_input
    os.environ['CERTBOT_VALIDATION'] = 'xyz'
    strato = CertbotStratoApi()
    requests_mock.get(strato.api_url, text=project_page)

    strato.get_package_id()

    assert strato.package_id == expected
Exemple #4
0
def test_parse_second_level_domain(test_input, expected):
    os.environ['CERTBOT_DOMAIN'] = test_input
    os.environ['CERTBOT_VALIDATION'] = 'xyz'

    strato = CertbotStratoApi()

    assert strato.second_level_domain_name == expected
Exemple #5
0
def test_reset_acme_record():
    strato = CertbotStratoApi()

    strato.set_amce_record()
    strato.reset_amce_record()

    assert len(strato.records) == 0
Exemple #6
0
def test_remove_record():
    strato = CertbotStratoApi()

    strato.add_txt_record('subdomain', 'TXT', 'myvalue')
    strato.remove_txt_record('subdomain', 'TXT')

    assert len(strato.records) == 0
Exemple #7
0
def test_records_are_empty_at_begin():
    strato = CertbotStratoApi()

    assert len(strato.records) == 0
def main():
    """Run authentification hook."""
    # get authentication data
    with open(
            os.path.dirname(__file__) + os.path.normcase('/strato-auth.json'),
            encoding='UTF-8',
    ) as file:
        auth = json.load(file)
        username = auth.get('username')
        password = auth.get('password')
        totp_secret = auth.get('totp_secret')
        totp_devicename = auth.get('totp_devicename')
        waiting_time = auth.get('waiting_time', 0)

    strato = CertbotStratoApi()
    if not strato.login(username, password, totp_secret, totp_devicename):
        print('ERROR: Strato login not accepted.')
        sys.exit(1)
    # Requests package id which package contains domain to be verified
    strato.get_package_id()
    # Requests all current TXT/CNAME/SPF/DKIM records from Strato
    strato.get_txt_records()
    # Add verification token record
    strato.set_amce_record()
    # Sets all TXT/CNAME/SPF/DKIM records with AMCE record in dns server
    strato.push_txt_records()
    # Sleep to give the DNS Server time to get ready
    time.sleep(waiting_time)