View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.fit.core;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.fail;
23  import static org.junit.jupiter.api.Assumptions.assumeTrue;
24  
25  import javax.ws.rs.core.Response;
26  import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
27  import org.apache.syncope.common.lib.SyncopeClientException;
28  import org.apache.syncope.common.lib.types.ClientExceptionType;
29  import org.apache.syncope.common.rest.api.service.OIDCJWKSService;
30  import org.apache.syncope.fit.AbstractITCase;
31  import org.junit.jupiter.api.BeforeAll;
32  import org.junit.jupiter.api.Test;
33  import org.springframework.http.HttpStatus;
34  
35  public class OIDCJWKSITCase extends AbstractITCase {
36  
37      private static OIDCJWKSService WA_OIDC_JWKS_SERVICE;
38  
39      @BeforeAll
40      public static void setup() {
41          assumeTrue(CLIENT_FACTORY.getContentType() == SyncopeClientFactoryBean.ContentType.JSON);
42  
43          WA_OIDC_JWKS_SERVICE = ANONYMOUS_CLIENT.getService(OIDCJWKSService.class);
44      }
45  
46      @Test
47      public void deleteGetSet() {
48          try {
49              OIDC_JWKS_SERVICE.delete();
50  
51              WA_OIDC_JWKS_SERVICE.get();
52              fail("Should not locate an OIDC JWKS");
53          } catch (SyncopeClientException e) {
54              assertEquals(ClientExceptionType.NotFound, e.getType());
55          }
56  
57          Response response = WA_OIDC_JWKS_SERVICE.generate("syncope", "RSA", 2048);
58          assertEquals(HttpStatus.CREATED.value(), response.getStatus());
59          try {
60              WA_OIDC_JWKS_SERVICE.generate("syncope", "RSA", 2048);
61              fail("Should not recreate an OIDC JWKS");
62          } catch (SyncopeClientException e) {
63              assertEquals(ClientExceptionType.EntityExists, e.getType());
64          }
65      }
66  }