2626import com .hivemq .api .auth .jwt .JwtAuthenticationProvider ;
2727import com .hivemq .api .auth .provider .IUsernamePasswordProvider ;
2828import com .hivemq .api .config .ApiJwtConfiguration ;
29+ import com .hivemq .api .error .ApiExceptionMapper ;
2930import com .hivemq .api .resources .impl .AuthenticationResourceImpl ;
3031import com .hivemq .edge .api .model .ApiBearerToken ;
3132import com .hivemq .edge .api .model .UsernamePasswordCredentials ;
3637import com .hivemq .http .core .HttpUrlConnectionClient ;
3738import com .hivemq .http .core .HttpUtils ;
3839import com .hivemq .http .error .ProblemDetails ;
40+ import jakarta .ws .rs .core .MediaType ;
3941import org .glassfish .jersey .server .ResourceConfig ;
4042import org .jetbrains .annotations .NotNull ;
4143import org .junit .AfterClass ;
4547import org .slf4j .Logger ;
4648import org .slf4j .LoggerFactory ;
4749
48- import jakarta .ws .rs .core .MediaType ;
4950import java .io .ByteArrayInputStream ;
5051import java .io .IOException ;
5152import java .util .HashSet ;
6162 */
6263public class ChainedAuthTests {
6364
64- protected final Logger logger = LoggerFactory .getLogger (ChainedAuthTests .class );
65-
6665 static final int TEST_HTTP_PORT = 8088 ;
6766 static final int CONNECT_TIMEOUT = 1000 ;
6867 static final int READ_TIMEOUT = 1000 ;
6968 static final String HTTP = "http" ;
70-
7169 protected static @ NotNull JaxrsHttpServer server ;
70+ protected final Logger logger = LoggerFactory .getLogger (ChainedAuthTests .class );
7271
7372 @ BeforeClass
7473 public static void setUp () throws Exception {
@@ -115,7 +114,8 @@ protected static String getTestServerAddress(final @NotNull String protocol, fin
115114 public void testAuthenticateValidUser () throws IOException {
116115
117116 final ObjectMapper mapper = new ObjectMapper ();
118- final UsernamePasswordCredentials creds = new UsernamePasswordCredentials ().userName ("testuser" ).password ("test" );
117+ final UsernamePasswordCredentials creds =
118+ new UsernamePasswordCredentials ().userName ("testuser" ).password ("test" );
119119 final HttpResponse response = HttpUrlConnectionClient .post (HttpUrlConnectionClient .JSON_HEADERS ,
120120 getTestServerAddress (HTTP , TEST_HTTP_PORT , "api/v1/auth/authenticate" ),
121121 new ByteArrayInputStream (mapper .writeValueAsBytes (creds )),
@@ -131,19 +131,17 @@ public void testAuthenticateValidUser() throws IOException {
131131
132132 @ Test
133133 public void testAuthenticateInvalidUser () throws IOException {
134-
135134 final ObjectMapper mapper = new ObjectMapper ();
136- final UsernamePasswordCredentials creds =
135+ final UsernamePasswordCredentials credentials =
137136 new UsernamePasswordCredentials ().userName ("testuser" ).password ("invalidpassword" );
138137 final HttpResponse response = HttpUrlConnectionClient .post (HttpUrlConnectionClient .JSON_HEADERS ,
139138 getTestServerAddress (HTTP , TEST_HTTP_PORT , "api/v1/auth/authenticate" ),
140- new ByteArrayInputStream (mapper .writeValueAsBytes (creds )),
139+ new ByteArrayInputStream (mapper .writeValueAsBytes (credentials )),
141140 CONNECT_TIMEOUT ,
142141 READ_TIMEOUT );
143-
144142 assertThat (response .getStatusCode ()).as ("Resource should NOT be accepted" ).isEqualTo (401 );
145143 assertThat (response .getContentType ()).as ("API authenticate response should be json" )
146- .startsWith ( MediaType . APPLICATION_JSON );
144+ .isEqualTo ( ApiExceptionMapper . APPLICATION_PROBLEM_JSON_CHARSET_UTF_8 );
147145 assertThat (mapper .readValue (response .getResponseBody (), ProblemDetails .class )
148146 .getErrors ()
149147 .get (0 )
@@ -155,7 +153,8 @@ public void testAuthenticateInvalidUser() throws IOException {
155153 public void testAuthenticatedTokenAllowsApiAccess () throws IOException {
156154
157155 final ObjectMapper mapper = new ObjectMapper ();
158- final UsernamePasswordCredentials creds = new UsernamePasswordCredentials ().userName ("testuser" ).password ("test" );
156+ final UsernamePasswordCredentials creds =
157+ new UsernamePasswordCredentials ().userName ("testuser" ).password ("test" );
159158 HttpResponse response = HttpUrlConnectionClient .post (HttpUrlConnectionClient .JSON_HEADERS ,
160159 getTestServerAddress (HTTP , TEST_HTTP_PORT , "api/v1/auth/authenticate" ),
161160 new ByteArrayInputStream (mapper .writeValueAsBytes (creds )),
0 commit comments