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