001/*
002 * acme4j - Java ACME client
003 *
004 * Copyright (C) 2017 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.it.pebble;
015
016import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
017import static org.assertj.core.api.Assertions.assertThat;
018
019import java.net.URI;
020
021import org.junit.jupiter.api.Test;
022import org.shredzone.acme4j.Session;
023import org.shredzone.acme4j.connector.Resource;
024import org.shredzone.acme4j.exception.AcmeException;
025
026/**
027 * Session related integration tests.
028 */
029public class SessionIT extends PebbleITBase {
030
031    @Test
032    public void testResources() throws AcmeException {
033        var session = new Session(pebbleURI());
034
035        assertIsPebbleUrl(session.resourceUrl(Resource.NEW_ACCOUNT));
036        assertIsPebbleUrl(session.resourceUrl(Resource.NEW_NONCE));
037        assertIsPebbleUrl(session.resourceUrl(Resource.NEW_ORDER));
038    }
039
040    @Test
041    public void testMetadata() throws AcmeException {
042        var session = new Session(pebbleURI());
043
044        var meta = session.getMetadata();
045        assertThat(meta).isNotNull();
046
047        assertThat(meta.getTermsOfService().orElseThrow())
048                .isEqualTo(URI.create("data:text/plain,Do%20what%20thou%20wilt"));
049        assertThat(meta.getWebsite()).isEmpty();
050        assertThat(meta.getCaaIdentities()).isEmpty();
051        assertThatJson(meta.getJSON().toString()).isEqualTo("{"
052                        + "'termsOfService': 'data:text/plain,Do%20what%20thou%20wilt',"
053                        + "'externalAccountRequired': false"
054                        + "}");
055    }
056
057}