@@ -110,7 +110,7 @@ public static Collection<Object[]> data() {
110
110
public TestTLS (String keyStoreFormat ,
111
111
String trustStoreFormat ,
112
112
boolean useV2Protocol ) {
113
- super (3 );
113
+ super (1 );
114
114
this .clientKeyStoreFormat = KeyStoreType .valueOf (keyStoreFormat );
115
115
this .clientTrustStoreFormat = KeyStoreType .valueOf (trustStoreFormat );
116
116
this .serverKeyStoreFormat = KeyStoreType .valueOf (keyStoreFormat );
@@ -504,9 +504,11 @@ public void testConnectToTLSClusterTLSClientWithAuthentication() throws Exceptio
504
504
505
505
/**
506
506
* Verify that a client without tls enabled can connect to a cluster with TLS.
507
+ * In the Default Bookie config, ONLY_SECURE_CLIENTS_ALLOWED is set to false.
508
+ * Therefore, the Bookie allows non-secure client connection.
507
509
*/
508
510
@ Test
509
- public void testConnectToTLSClusterNonTLSClient () throws Exception {
511
+ public void testConnectToTLSClusterNonTLSClient1 () throws Exception {
510
512
ClientConfiguration conf = new ClientConfiguration (baseClientConf );
511
513
conf .setTLSProviderFactoryClass (null );
512
514
try {
@@ -516,6 +518,86 @@ public void testConnectToTLSClusterNonTLSClient() throws Exception {
516
518
}
517
519
}
518
520
521
+ /**
522
+ * Verify that a client without tls enabled can NOT connect to a cluster with TLS,
523
+ * if ONLY_SECURE_CLIENTS_ALLOWED is set in the Bookie config.
524
+ */
525
+ @ Test
526
+ public void testConnectToTLSClusterNonTLSClient2 () throws Exception {
527
+ // Set client without TLS
528
+ ClientConfiguration conf = new ClientConfiguration (baseClientConf );
529
+ conf .setTLSProviderFactoryClass (null );
530
+ try {
531
+ // Enable the feature to only allow secure clients.
532
+ restartBookies (c -> {
533
+ c .setOnlySecureClientConnectionAllowed (true );
534
+ return c ;
535
+ });
536
+ testClient (conf , numBookies );
537
+ fail ("non tls client should not be able to connect to tls enabled bookies" );
538
+ } catch (BKException .BKNotEnoughBookiesException nnbe ) {
539
+ // Correct response.
540
+ } catch (BKException .BKUnauthorizedAccessException ue ) {
541
+ // Correct response.
542
+ }
543
+ }
544
+
545
+ /**
546
+ * Verify that the Read from the non-Secure Client throws BKSecurityException
547
+ * if ONLY_SECURE_CLIENTS_ALLOWED is set in the Bookie config.
548
+ */
549
+ @ Test
550
+ public void testReadwithNonTLSBookie () throws Exception {
551
+
552
+ /* TestTLS tests for V3 and V2 protocols together
553
+ * We should be able to create a ledger when its v3 and setOnlySecureClientConnectionAllowed(true)
554
+ * We shouldn't be able to do any create / read when its v2 and setOnlySecureClientConnectionAllowed(true)
555
+ * since v2 does not support TLS.
556
+ */
557
+ if (useV2Protocol ) {
558
+ return ;
559
+ }
560
+
561
+ // Enable the feature to only allow secure clients.
562
+ ClientConfiguration conf = new ClientConfiguration (baseClientConf );
563
+ long lid = 0 ;
564
+ try {
565
+ restartBookies (c -> {
566
+ c .setOnlySecureClientConnectionAllowed (true );
567
+ return c ;
568
+ });
569
+ // Create the Ledger
570
+ BookKeeper client = new BookKeeper (conf );
571
+ byte [] passwd = "testPassword" .getBytes ();
572
+ int numEntries = 10 ;
573
+ byte [] testEntry = "testEntry" .getBytes ();
574
+ try (LedgerHandle lh = client .createLedger (numBookies , numBookies , DigestType .CRC32 , passwd );) {
575
+ for (int i = 0 ; i <= numEntries ; i ++) {
576
+ lh .addEntry (testEntry );
577
+ }
578
+ lid = lh .getId ();
579
+ }
580
+ } catch (BKException .BKNotEnoughBookiesException nnbe ) {
581
+ fail ("tls client could not create the ledger" );
582
+ }
583
+ // nonTLS client should not be able to read the ledger
584
+ conf .setTLSProviderFactoryClass (null );
585
+ try {
586
+ BookKeeper client = new BookKeeper (conf );
587
+ byte [] passwd = "testPassword" .getBytes ();
588
+ int numEntries = 10 ;
589
+ byte [] testEntry = "testEntry" .getBytes ();
590
+ try (LedgerHandle lh = client .openLedger (lid , DigestType .CRC32 , passwd );) {
591
+ Enumeration <LedgerEntry > entries = lh .readEntries (0 , numEntries );
592
+ fail ("The Read should've failed with BKSecurityException" );
593
+ }
594
+ } catch (BKException .BKSecurityException se ) {
595
+ // Correct Response.
596
+ } catch (BKException .BKUnauthorizedAccessException ue ) {
597
+ // Correct response.
598
+ }
599
+ }
600
+
519
601
/**
520
602
* Verify that a client will fail to connect to a server if it has asked for TLS, but it is not available.
521
603
*/
@@ -540,7 +622,7 @@ public void testClientWantsTLSNoServersHaveIt() throws Exception {
540
622
* bookies with TLS enabled in the cluster, although few bookies do not have TLS enabled.
541
623
*/
542
624
@ Test
543
- public void testTLSClientButOnlyFewTLSServers () throws Exception {
625
+ public void testTLSClientButOnlyFewTLSServers1 () throws Exception {
544
626
// disable TLS on initial set of bookies
545
627
restartBookies (c -> {
546
628
c .setTLSProviderFactoryClass (null );
0 commit comments