@@ -439,25 +439,47 @@ public void testBearerTokenAuth() throws Exception {
439439 .map (s -> Base64 .getEncoder ().encodeToString (s .getBytes (StandardCharsets .UTF_8 )))
440440 .reduce ((s1 , s2 ) -> s1 + "." + s2 ).get ();
441441
442- // WIP
443- ByteBuffer buffer = ByteBuffer .allocate (4 );
444- buffer .put ((byte ) 1 );
442+ // From wireshark dump as C Array
443+ char select_server_info [] = { /* Packet 11901 */
444+ 0x03 , 0x04 , 0x75 , 0x73 , 0x65 , 0x72 , 0x08 , 0x74 ,
445+ 0x69 , 0x6d , 0x65 , 0x7a , 0x6f , 0x6e , 0x65 , 0x07 ,
446+ 0x76 , 0x65 , 0x72 , 0x73 , 0x69 , 0x6f , 0x6e , 0x06 ,
447+ 0x53 , 0x74 , 0x72 , 0x69 , 0x6e , 0x67 , 0x06 , 0x53 ,
448+ 0x74 , 0x72 , 0x69 , 0x6e , 0x67 , 0x06 , 0x53 , 0x74 ,
449+ 0x72 , 0x69 , 0x6e , 0x67 , 0x07 , 0x64 , 0x65 , 0x66 ,
450+ 0x61 , 0x75 , 0x6c , 0x74 , 0x03 , 0x55 , 0x54 , 0x43 ,
451+ 0x0b , 0x32 , 0x34 , 0x2e , 0x33 , 0x2e , 0x31 , 0x2e ,
452+ 0x32 , 0x36 , 0x37 , 0x32 };
453+
454+ char select1_res [] = { /* Packet 11909 */
455+ 0x01 , 0x01 , 0x31 , 0x05 , 0x55 , 0x49 , 0x6e , 0x74 ,
456+ 0x38 , 0x01 };
445457
446458 mockServer .addStubMapping (WireMock .post (WireMock .anyUrl ())
447459 .withHeader ("Authorization" , WireMock .equalTo ("Bearer " + jwtToken1 ))
460+ .withRequestBody (WireMock .matching (".*SELECT 1.*" ))
448461 .willReturn (
449- WireMock .ok (buffer . toString ( ))
462+ WireMock .ok (new String ( select1_res ))
450463 .withHeader ("X-ClickHouse-Summary" ,
451464 "{ \" read_bytes\" : \" 10\" , \" read_rows\" : \" 1\" }" )).build ());
452465
466+ mockServer .addStubMapping (WireMock .post (WireMock .anyUrl ())
467+ .withHeader ("Authorization" , WireMock .equalTo ("Bearer " + jwtToken1 ))
468+ .withRequestBody (WireMock .equalTo ("SELECT currentUser() AS user, timezone() AS timezone, version() AS version LIMIT 1" ))
469+ .willReturn (
470+ WireMock .ok (new String (select_server_info ))
471+ .withHeader ("X-ClickHouse-Summary" ,
472+ "{ \" read_bytes\" : \" 10\" , \" read_rows\" : \" 1\" }" )).build ());
473+
453474 Properties properties = new Properties ();
454475 properties .put ("access_token" , jwtToken1 );
455476 properties .put ("compress" , "false" );
456477 String jdbcUrl = "jdbc:clickhouse://" + "localhost" + ":" + mockServer .port ();
457478 try (Connection conn = new ConnectionImpl (jdbcUrl , properties );
458479 Statement stmt = conn .createStatement ();
459480 ResultSet rs = stmt .executeQuery ("SELECT 1" )) {
460-
481+ Assert .assertTrue (rs .next ());
482+ Assert .assertEquals (rs .getInt (1 ), 1 );
461483 }
462484 } finally {
463485 mockServer .stop ();
0 commit comments