001/*
002 * acme4j - Java ACME client
003 *
004 * Copyright (C) 2024 Richard "Shred" Körber
005 *   http://acme4j.shredzone.org
006 *
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
013 */
014package org.shredzone.acme4j.provider.zerossl;
015
016import static org.assertj.core.api.Assertions.assertThat;
017import static org.junit.jupiter.api.Assertions.assertThrows;
018import static org.shredzone.acme4j.toolbox.TestUtils.url;
019
020import java.net.URI;
021import java.net.URISyntaxException;
022
023import org.assertj.core.api.AutoCloseableSoftAssertions;
024import org.junit.jupiter.api.Test;
025
026/**
027 * Unit tests for {@link ZeroSSLAcmeProvider}.
028 */
029public class ZeroSSLAcmeProviderTest {
030
031    private static final String V02_DIRECTORY_URL = "https://acme.zerossl.com/v2/DV90";
032
033    /**
034     * Tests if the provider accepts the correct URIs.
035     */
036    @Test
037    public void testAccepts() throws URISyntaxException {
038        var provider = new ZeroSSLAcmeProvider();
039
040        try (var softly = new AutoCloseableSoftAssertions()) {
041            softly.assertThat(provider.accepts(new URI("acme://zerossl.com"))).isTrue();
042            softly.assertThat(provider.accepts(new URI("acme://zerossl.com/"))).isTrue();
043            softly.assertThat(provider.accepts(new URI("acme://example.com"))).isFalse();
044            softly.assertThat(provider.accepts(new URI("http://example.com/acme"))).isFalse();
045            softly.assertThat(provider.accepts(new URI("https://example.com/acme"))).isFalse();
046        }
047    }
048
049    /**
050     * Test if acme URIs are properly resolved.
051     */
052    @Test
053    public void testResolve() throws URISyntaxException {
054        var provider = new ZeroSSLAcmeProvider();
055
056        assertThat(provider.resolve(new URI("acme://zerossl.com"))).isEqualTo(url(V02_DIRECTORY_URL));
057        assertThat(provider.resolve(new URI("acme://zerossl.com/"))).isEqualTo(url(V02_DIRECTORY_URL));
058
059        assertThrows(IllegalArgumentException.class, () -> provider.resolve(new URI("acme://zerossl.com/v99")));
060    }
061
062}