@@ -512,3 +512,90 @@ func TestExclusiveLock(t *testing.T) {
512
512
t .Fatalf ("expecting keeper reporting that failed to take an exclusive lock on data dir" )
513
513
}
514
514
}
515
+
516
+ func TestPasswordTrailingNewLine (t * testing.T ) {
517
+ t .Parallel ()
518
+
519
+ dir , err := ioutil .TempDir ("" , "" )
520
+ if err != nil {
521
+ t .Fatalf ("unexpected err: %v" , err )
522
+ }
523
+ defer os .RemoveAll (dir )
524
+
525
+ tstore , err := NewTestStore (t , dir )
526
+ if err != nil {
527
+ t .Fatalf ("unexpected err: %v" , err )
528
+ }
529
+ if err := tstore .Start (); err != nil {
530
+ t .Fatalf ("unexpected err: %v" , err )
531
+ }
532
+ if err := tstore .WaitUp (10 * time .Second ); err != nil {
533
+ t .Fatalf ("error waiting on store up: %v" , err )
534
+ }
535
+ storeEndpoints := fmt .Sprintf ("%s:%s" , tstore .listenAddress , tstore .port )
536
+ defer tstore .Stop ()
537
+
538
+ clusterName := uuid .NewV4 ().String ()
539
+
540
+ u := uuid .NewV4 ()
541
+ id := fmt .Sprintf ("%x" , u [:4 ])
542
+
543
+ pgSUPassword := "stolon_superuserpassword\n "
544
+ pgReplPassword := "stolon_replpassword\n "
545
+
546
+ tk , err := NewTestKeeperWithID (t , dir , id , clusterName , pgSUUsername , pgSUPassword , pgReplUsername , pgReplPassword , tstore .storeBackend , storeEndpoints )
547
+ if err != nil {
548
+ t .Fatalf ("unexpected err: %v" , err )
549
+ }
550
+ if err := tk .StartExpect (); err != nil {
551
+ t .Fatalf ("unexpected err: %v" , err )
552
+ }
553
+
554
+ if err := tk .cmd .ExpectTimeout ("superuser password contain trailing new line, removing" , 30 * time .Second ); err != nil {
555
+ t .Fatalf (`expecting keeper reporting "superuser password contain trailing new line, removing"` )
556
+ }
557
+ if err := tk .cmd .ExpectTimeout ("replication user password contain trailing new line, removing" , 30 * time .Second ); err != nil {
558
+ t .Fatalf (`expecting keeper reporting "replication user password contain trailing new line, removing"` )
559
+ }
560
+ tk .Stop ()
561
+
562
+ pgSUPassword = "stolon_superuserpassword\n "
563
+ pgReplPassword = "\n "
564
+
565
+ tk , err = NewTestKeeperWithID (t , dir , id , clusterName , pgSUUsername , pgSUPassword , pgReplUsername , pgReplPassword , tstore .storeBackend , storeEndpoints )
566
+ if err != nil {
567
+ t .Fatalf ("unexpected err: %v" , err )
568
+ }
569
+ if err := tk .StartExpect (); err != nil {
570
+ t .Fatalf ("unexpected err: %v" , err )
571
+ }
572
+
573
+ if err := tk .cmd .ExpectTimeout ("replication user password contain trailing new line, removing" , 30 * time .Second ); err != nil {
574
+ t .Fatalf (`expecting keeper reporting "replication user password contain trailing new line, removing"` )
575
+ }
576
+ if err := tk .cmd .ExpectTimeout ("replication user password is empty after removing trailing new line" , 30 * time .Second ); err != nil {
577
+ t .Fatalf (`expecting keeper reporting "replication user password is empty after removing trailing new line"` )
578
+ }
579
+
580
+ tk .Stop ()
581
+
582
+ pgSUPassword = "\n "
583
+ pgReplPassword = "stolon_replpassword\n "
584
+
585
+ tk , err = NewTestKeeperWithID (t , dir , id , clusterName , pgSUUsername , pgSUPassword , pgReplUsername , pgReplPassword , tstore .storeBackend , storeEndpoints )
586
+ if err != nil {
587
+ t .Fatalf ("unexpected err: %v" , err )
588
+ }
589
+ if err := tk .StartExpect (); err != nil {
590
+ t .Fatalf ("unexpected err: %v" , err )
591
+ }
592
+
593
+ if err := tk .cmd .ExpectTimeout ("superuser password contain trailing new line, removing" , 30 * time .Second ); err != nil {
594
+ t .Fatalf (`expecting keeper reporting "superuser password contain trailing new line, removing"` )
595
+ }
596
+ if err := tk .cmd .ExpectTimeout ("superuser password is empty after removing trailing new line" , 30 * time .Second ); err != nil {
597
+ t .Fatalf (`expecting keeper reporting "superuser password is empty after removing trailing new line"` )
598
+ }
599
+
600
+ tk .Stop ()
601
+ }
0 commit comments