1 22 package org.jboss.test.jbossmq.test; 23 24 import javax.management.ObjectName ; 25 import junit.framework.Assert; 26 import junit.framework.Test; 27 import junit.framework.TestSuite; 28 import org.jboss.test.JBossTestSetup; 29 import org.jboss.test.jbossmq.MQBase; 30 37 public class SecurityUnitTestCase extends MQBase 38 { 39 public SecurityUnitTestCase(String name) 40 { 41 super(name); 42 } 43 44 public void runLoginTest() throws Exception 45 { 46 TopicWorker sub1 = null; 47 TopicWorker pub1 = null; 48 try 49 { 50 drainTopic(); 51 int ic = 5; 52 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "USER_NR", 0, ic); 53 sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1); 54 sub1.setUser("john", "needle"); 55 Thread t1 = new Thread (sub1); 56 t1.start(); 57 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 59 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic); 60 pub1.connect(); 61 pub1.publish(); 62 Assert.assertEquals("Publisher did not publish correct number of messages " + pub1.getMessageHandled(), ic, 63 pub1.getMessageHandled()); 64 log.debug("Sleeping for " + ((ic * 10) / 60000) + " minutes"); 66 sleep(ic * 100); 67 Assert.assertEquals("Subscriber did not get correct number of messages " + sub1.getMessageHandled(), ic, sub1 68 .getMessageHandled()); 69 sub1.close(); 70 pub1.close(); 71 } 72 catch (Throwable t) 73 { 74 if (t instanceof junit.framework.AssertionFailedError) 75 throw (junit.framework.AssertionFailedError) t; 76 log.error("Error in test: " + t, t); 77 throw new Exception (t.getMessage()); 78 } 79 finally 80 { 81 try 82 { 83 if (sub1 != null) 84 sub1.close(); 85 } 86 catch (Exception ex) 87 { 88 } 89 try 90 { 91 if (pub1 != null) 92 pub1.close(); 93 } 94 catch (Exception ex) 95 { 96 } 97 } 98 } 99 100 107 public void runLoginNoCred() throws Exception 108 { 109 TopicWorker pub1 = null; 110 try 111 { 112 drainTopic(); 113 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, null, 0); 114 pub1.connect(); 115 } 116 catch (Exception ex) 117 { 118 Assert.fail("Could lot login without any cred"); 119 } 120 finally 121 { 122 try 123 { 124 pub1.close(); 125 } 126 catch (Exception ex) 127 { 128 } 129 } 130 } 131 132 public void runLoginValidCred() throws Exception 133 { 134 TopicWorker pub1 = null; 135 try 136 { 137 drainTopic(); 138 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, null, 0); 139 pub1.setUser("john", "needle"); 140 pub1.connect(); 141 } 142 catch (Exception ex) 143 { 144 Assert.fail("Could lot login with valid cred"); 145 } 146 finally 147 { 148 try 149 { 150 pub1.close(); 151 } 152 catch (Exception ex) 153 { 154 } 155 } 156 } 157 158 public void runLoginInvalidPwd() throws Exception 159 { 160 TopicWorker pub1 = null; 161 try 162 { 163 drainTopic(); 164 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, null, 0); 165 pub1.setUser("john", "bogus"); 166 Exception e = null; 167 try 168 { 169 pub1.connect(); 170 } 171 catch (Exception ex) 172 { 173 e = ex; 174 } 175 log.debug(e); 176 Assert.assertTrue("Loggin in with invalid password did not throw correct exception", 177 e instanceof javax.jms.JMSSecurityException ); 178 } 179 finally 180 { 181 try 182 { 183 pub1.close(); 184 } 185 catch (Exception ex) 186 { 187 } 188 } 189 } 190 191 public void runLoginInvalidCred() throws Exception 192 { 193 TopicWorker pub1 = null; 194 try 195 { 196 drainTopic(); 197 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, null, 0); 198 pub1.setUser("bogus", "bogus"); 199 Exception e = null; 200 try 201 { 202 pub1.connect(); 203 } 204 catch (Exception ex) 205 { 206 e = ex; 207 } 208 log.debug(e); 209 Assert.assertTrue("Loggin in with invalid user did not throw correct exception", 210 e instanceof javax.jms.JMSSecurityException ); 211 } 212 finally 213 { 214 try 215 { 216 pub1.close(); 217 } 218 catch (Exception ex) 219 { 220 } 221 } 222 } 223 224 234 public void runClientIDNormalTest() throws Exception 235 { 236 TopicWorker pub1 = null; 237 try 238 { 239 drainTopic(); 240 int ic = 5; 241 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 243 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic); 244 pub1.connect(); 245 pub1.publish(); 246 Assert.assertTrue("Client did not get a valid clientID", pub1.connection.getClientID().startsWith("ID")); 247 pub1.close(); 248 } 249 catch (Throwable t) 250 { 251 if (t instanceof junit.framework.AssertionFailedError) 252 throw (junit.framework.AssertionFailedError) t; 253 log.error("Error in test: " + t, t); 254 throw new Exception (t.getMessage()); 255 } 256 finally 257 { 258 try 259 { 260 pub1.close(); 261 } 262 catch (Exception ex) 263 { 264 } 265 } 266 } 267 268 public void runClientIDPreconfTest() throws Exception 269 { 270 TopicWorker pub1 = null; 271 try 272 { 273 drainTopic(); 274 int ic = 5; 275 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 277 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic); 278 pub1.setUser("john", "needle"); 279 pub1.connect(); 280 pub1.publish(); 281 Assert.assertEquals("Client did not get a valid clientID", "DurableSubscriberExample", pub1.connection 282 .getClientID()); 283 pub1.close(); 284 } 285 catch (Throwable t) 286 { 287 if (t instanceof junit.framework.AssertionFailedError) 288 throw (junit.framework.AssertionFailedError) t; 289 log.error("Error in test: " + t, t); 290 throw new Exception (t.getMessage()); 291 } 292 finally 293 { 294 try 295 { 296 pub1.close(); 297 } 298 catch (Exception ex) 299 { 300 } 301 } 302 } 303 304 public void runClientIDSetTest() throws Exception 305 { 306 TopicWorker pub1 = null; 307 try 308 { 309 drainTopic(); 310 int ic = 5; 311 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 313 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic); 314 pub1.setClientID("myId"); 315 pub1.connect(); 316 pub1.publish(); 317 Assert.assertEquals("Client did not get a valid clientID", "myId", pub1.connection.getClientID()); 318 pub1.close(); 319 } 320 catch (Throwable t) 321 { 322 if (t instanceof junit.framework.AssertionFailedError) 323 throw (junit.framework.AssertionFailedError) t; 324 log.error("Error in test: " + t, t); 325 throw new Exception (t.getMessage()); 326 } 327 finally 328 { 329 try 330 { 331 pub1.close(); 332 } 333 catch (Exception ex) 334 { 335 } 336 } 337 } 338 339 public void runClientIDSetSteelPreconf() throws Exception 340 { 341 TopicWorker pub1 = null; 342 try 343 { 344 drainTopic(); 345 int ic = 5; 346 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 348 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic); 349 pub1.setClientID("DurableSubscriberExample"); 350 Exception e = null; 351 try 352 { 353 pub1.connect(); 354 } 355 catch (Exception ex) 356 { 357 e = ex; 358 } 359 log.debug(e); 360 Assert.assertTrue("Setting a clientID wich is preconfigured did not throw correct exception", 361 e instanceof javax.jms.InvalidClientIDException ); 362 pub1.close(); 363 } 364 catch (Throwable t) 365 { 366 if (t instanceof junit.framework.AssertionFailedError) 367 throw (junit.framework.AssertionFailedError) t; 368 log.error("Error in test: " + t, t); 369 throw new Exception (t.getMessage()); 370 } 371 finally 372 { 373 try 374 { 375 pub1.close(); 376 } 377 catch (Exception ex) 378 { 379 } 380 } 381 } 382 383 public void runClientIDSetAfterInvoke() throws Exception 384 { 385 TopicWorker pub1 = null; 386 try 387 { 388 drainTopic(); 389 int ic = 5; 390 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 392 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic); 393 pub1.connect(); 394 pub1.publish(); 395 Exception e = null; 396 try 397 { 398 pub1.connection.setClientID("myID"); 399 } 400 catch (Exception ex) 401 { 402 e = ex; 403 } 404 log.debug(e); 405 Assert.assertTrue("Setting a clientID after connection is used did not throw correct exception: " + e, 406 e instanceof javax.jms.IllegalStateException ); 407 pub1.close(); 408 } 409 catch (Throwable t) 410 { 411 if (t instanceof junit.framework.AssertionFailedError) 412 throw (junit.framework.AssertionFailedError) t; 413 log.error("Error in test: " + t, t); 414 throw new Exception (t.getMessage()); 415 } 416 finally 417 { 418 try 419 { 420 pub1.close(); 421 } 422 catch (Exception ex) 423 { 424 } 425 } 426 } 427 428 453 public void runAuzValidTopicPublisher() throws Exception 454 { 455 TopicWorker pub1 = null; 456 try 457 { 458 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 459 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, 1); 460 pub1.setUser("john", "needle"); 461 pub1.connect(); 462 pub1.publish(); 463 } 464 catch (Exception ex) 465 { 466 Assert.fail("Could not publish to valid destination"); 467 } 468 finally 469 { 470 try 471 { 472 pub1.close(); 473 } 474 catch (Exception ex) 475 { 476 } 477 } 478 } 479 480 public void runAuzValidTopicPublisherTransaction() throws Exception 481 { 482 TopicWorker pub1 = null; 483 try 484 { 485 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 486 pub1 = new TopicWorker(PUBLISHER, TRANS_INDIVIDUAL, c1, 1); 487 pub1.setUser("john", "needle"); 488 pub1.connect(); 489 pub1.publish(); 490 } 491 catch (Exception ex) 492 { 493 Assert.fail("Could not publish to valid destination"); 494 } 495 finally 496 { 497 try 498 { 499 pub1.close(); 500 } 501 catch (Exception ex) 502 { 503 } 504 } 505 } 506 507 public void runAuzInvalidTopicPublisher() throws Exception 508 { 509 TopicWorker pub1 = null; 510 try 511 { 512 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 513 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, 1); 514 pub1.setUser("nobody", "nobody"); 515 pub1.connect(); 516 Exception e = null; 517 try 518 { 519 pub1.publish(); 520 } 521 catch (Exception ex) 522 { 523 e = ex; 524 } 525 log.debug(e); 526 Assert.assertTrue("Unauz topic publishing throw wrong exception: " + e, 527 e instanceof javax.jms.JMSSecurityException ); 528 } 529 finally 530 { 531 try 532 { 533 pub1.close(); 534 } 535 catch (Exception ex) 536 { 537 } 538 } 539 } 540 541 public void runAuzInvalidTopicPublisherTransaction() throws Exception 542 { 543 TopicWorker pub1 = null; 544 try 545 { 546 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 547 pub1 = new TopicWorker(PUBLISHER, TRANS_INDIVIDUAL, c1, 1); 548 pub1.setUser("nobody", "nobody"); 549 pub1.connect(); 550 Exception e = null; 551 try 552 { 553 pub1.publish(); 554 } 555 catch (Exception ex) 556 { 557 e = ex; 558 } 559 log.debug(e); 560 Assert.assertTrue("Unauz topic publishing throw wrong exception: " + e, 561 e instanceof javax.jms.JMSSecurityException ); 562 } 563 finally 564 { 565 try 566 { 567 pub1.close(); 568 } 569 catch (Exception ex) 570 { 571 } 572 } 573 } 574 575 public void runAuzValidTopicSubscriber() throws Exception 576 { 577 TopicWorker sub1 = null; 578 try 579 { 580 drainTopic(); 581 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "USER_NR", 0, 1); 582 sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1); 583 sub1.setUser("john", "needle"); 584 Thread t1 = new Thread (sub1); 585 t1.start(); 586 sleep(1000L); 587 Exception ex = sub1.getException(); 588 t1.interrupt(); 589 Assert.assertTrue("Autz topic subscriber did not work", ex == null); 590 } 591 finally 592 { 593 try 594 { 595 sub1.close(); 596 } 597 catch (Exception ex) 598 { 599 } 600 } 601 } 602 603 public void runAuzValidTopicSubscriberTransaction() throws Exception 604 { 605 TopicWorker sub1 = null; 606 try 607 { 608 drainTopic(); 609 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "USER_NR", 0, 1); 610 sub1 = new TopicWorker(SUBSCRIBER, TRANS_INDIVIDUAL, f1); 611 sub1.setUser("john", "needle"); 612 Thread t1 = new Thread (sub1); 613 t1.start(); 614 sleep(1000L); 615 Exception ex = sub1.getException(); 616 t1.interrupt(); 617 Assert.assertTrue("Autz topic subscriber did not work", ex == null); 618 } 619 finally 620 { 621 try 622 { 623 sub1.close(); 624 } 625 catch (Exception ex) 626 { 627 } 628 } 629 } 630 631 public void runAuzInvalidTopicSubscriber() throws Exception 632 { 633 TopicWorker sub1 = null; 634 try 635 { 636 drainTopic(); 637 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "USER_NR", 0, 1); 638 sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1); 639 sub1.setUser("nobody", "nobody"); 640 Thread t1 = new Thread (sub1); 641 t1.start(); 642 sleep(1000L); 643 Exception ex = sub1.getException(); 644 t1.interrupt(); 645 Assert.assertTrue("Unautz topic subscriber throw wrong exception: " + ex, 646 ex instanceof javax.jms.JMSSecurityException ); 647 } 648 finally 649 { 650 try 651 { 652 sub1.close(); 653 } 654 catch (Exception ex) 655 { 656 } 657 } 658 } 659 660 public void runAuzInvalidTopicSubscriberTransaction() throws Exception 661 { 662 TopicWorker sub1 = null; 663 try 664 { 665 drainTopic(); 666 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "USER_NR", 0, 1); 667 sub1 = new TopicWorker(SUBSCRIBER, TRANS_INDIVIDUAL, f1); 668 sub1.setUser("nobody", "nobody"); 669 Thread t1 = new Thread (sub1); 670 t1.start(); 671 sleep(1000L); 672 Exception ex = sub1.getException(); 673 t1.interrupt(); 674 Assert.assertTrue("Unautz topic subscriber throw wrong exception: " + ex, 675 ex instanceof javax.jms.JMSSecurityException ); 676 } 677 finally 678 { 679 try 680 { 681 sub1.close(); 682 } 683 catch (Exception ex) 684 { 685 } 686 } 687 } 688 689 public void runAuzValidQueueSender() throws Exception 690 { 691 QueueWorker pub1 = null; 692 try 693 { 694 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 695 pub1 = new QueueWorker(PUBLISHER, TRANS_NONE, c1, 1); 696 pub1.setUser("john", "needle"); 697 pub1.connect(); 698 pub1.publish(); 699 } 700 catch (Exception ex) 701 { 702 Assert.fail("Could not publish to valid destination"); 703 } 704 finally 705 { 706 try 707 { 708 pub1.close(); 709 } 710 catch (Exception ex) 711 { 712 } 713 } 714 } 715 716 public void runAuzValidQueueSenderTransaction() throws Exception 717 { 718 QueueWorker pub1 = null; 719 try 720 { 721 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 722 pub1 = new QueueWorker(PUBLISHER, TRANS_INDIVIDUAL, c1, 1); 723 pub1.setUser("john", "needle"); 724 pub1.connect(); 725 pub1.publish(); 726 } 727 catch (Exception ex) 728 { 729 Assert.fail("Could not publish to valid destination"); 730 } 731 finally 732 { 733 try 734 { 735 pub1.close(); 736 } 737 catch (Exception ex) 738 { 739 } 740 } 741 } 742 743 public void runAuzInvalidQueueSender() throws Exception 744 { 745 QueueWorker pub1 = null; 746 try 747 { 748 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 749 pub1 = new QueueWorker(PUBLISHER, TRANS_NONE, c1, 1); 750 pub1.setUser("nobody", "nobody"); 751 pub1.connect(); 752 Exception e = null; 753 try 754 { 755 pub1.publish(); 756 } 757 catch (Exception ex) 758 { 759 e = ex; 760 } 761 log.debug(e); 762 Assert.assertTrue("Unauz queue publishing throw wrong exception: " + e, 763 e instanceof javax.jms.JMSSecurityException ); 764 } 765 finally 766 { 767 try 768 { 769 pub1.close(); 770 } 771 catch (Exception ex) 772 { 773 } 774 } 775 } 776 777 public void runAuzInvalidQueueSenderTransaction() throws Exception 778 { 779 QueueWorker pub1 = null; 780 try 781 { 782 IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0); 783 pub1 = new QueueWorker(PUBLISHER, TRANS_INDIVIDUAL, c1, 1); 784 pub1.setUser("nobody", "nobody"); 785 pub1.connect(); 786 Exception e = null; 787 try 788 { 789 pub1.publish(); 790 } 791 catch (Exception ex) 792 { 793 e = ex; 794 } 795 log.debug(e); 796 Assert.assertTrue("Unauz queue publishing throw wrong exception: " + e, 797 e instanceof javax.jms.JMSSecurityException ); 798 } 799 finally 800 { 801 try 802 { 803 pub1.close(); 804 } 805 catch (Exception ex) 806 { 807 } 808 } 809 } 810 811 public void runAuzValidQueueReceiver() throws Exception 812 { 813 QueueWorker sub1 = null; 814 try 815 { 816 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "USER_NR", 0, 1); 817 sub1 = new QueueWorker(GETTER, TRANS_NONE, f1); 818 sub1.setUser("john", "needle"); 819 sub1.connect(); 820 Exception ex = null; 821 try 822 { 823 sub1.get(); 824 } 825 catch (Exception e) 826 { 827 ex = e; 828 log.error("ValidQueueReceiver got an exception: " + e, e); 829 } 830 Assert.assertTrue("Autz queue receiver did not work", ex == null); 831 } 832 finally 833 { 834 try 835 { 836 sub1.close(); 837 } 838 catch (Exception ex) 839 { 840 } 841 } 842 } 843 844 public void runAuzValidQueueReceiverTransaction() throws Exception 845 { 846 QueueWorker sub1 = null; 847 try 848 { 849 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "USER_NR", 0, 1); 850 sub1 = new QueueWorker(GETTER, TRANS_INDIVIDUAL, f1); 851 sub1.setUser("john", "needle"); 852 sub1.connect(); 853 Exception ex = null; 854 try 855 { 856 sub1.get(); 857 } 858 catch (Exception e) 859 { 860 ex = e; 861 log.error("ValidQueueReceiver got an exception: " + e, e); 862 } 863 Assert.assertTrue("Autz queue receiver did not work", ex == null); 864 } 865 finally 866 { 867 try 868 { 869 sub1.close(); 870 } 871 catch (Exception ex) 872 { 873 } 874 } 875 } 876 877 public void runAuzInvalidQueueReceiver() throws Exception 878 { 879 QueueWorker sub1 = null; 880 try 881 { 882 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "USER_NR", 0, 1); 883 sub1 = new QueueWorker(GETTER, TRANS_NONE, f1); 884 sub1.setUser("nobody", "nobody"); 885 sub1.connect(); 886 Exception ex = null; 887 try 888 { 889 sub1.get(); 890 } 891 catch (Exception e) 892 { 893 ex = e; 894 } 895 Assert.assertTrue("Unautz queue receiver throw wrong exception: " + ex, 896 ex instanceof javax.jms.JMSSecurityException ); 897 } 898 finally 899 { 900 try 901 { 902 sub1.close(); 903 } 904 catch (Exception ex) 905 { 906 } 907 } 908 } 909 910 public void runAuzInvalidQueueReceiverTransaction() throws Exception 911 { 912 QueueWorker sub1 = null; 913 try 914 { 915 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "USER_NR", 0, 1); 916 sub1 = new QueueWorker(GETTER, TRANS_INDIVIDUAL, f1); 917 sub1.setUser("nobody", "nobody"); 918 sub1.connect(); 919 Exception ex = null; 920 try 921 { 922 sub1.get(); 923 } 924 catch (Exception e) 925 { 926 ex = e; 927 } 928 Assert.assertTrue("Unautz queue receiver throw wrong exception: " + ex, 929 ex instanceof javax.jms.JMSSecurityException ); 930 } 931 finally 932 { 933 try 934 { 935 sub1.close(); 936 } 937 catch (Exception ex) 938 { 939 } 940 } 941 } 942 943 public void runAuzValidQueueBrowser() throws Exception 944 { 945 QueueWorker sub1 = null; 946 try 947 { 948 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "USER_NR", 0, 1); 949 sub1 = new QueueWorker(GETTER, TRANS_NONE, f1); 950 sub1.setUser("john", "needle"); 951 sub1.connect(); 952 Exception ex = null; 953 try 954 { 955 sub1.browse(); 956 } 957 catch (Exception e) 958 { 959 ex = e; 960 log.error("ValidQueueBrowser throw exception: " + e, e); 961 } 962 Assert.assertTrue("Autz queue receiver did not work", ex == null); 963 } 964 finally 965 { 966 try 967 { 968 sub1.close(); 969 } 970 catch (Exception ex) 971 { 972 } 973 } 974 } 975 976 public void runAuzInvalidQueueBrowser() throws Exception 977 { 978 QueueWorker sub1 = null; 979 try 980 { 981 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "USER_NR", 0, 1); 982 sub1 = new QueueWorker(GETTER, TRANS_NONE, f1); 983 sub1.setUser("nobody", "nobody"); 984 sub1.connect(); 985 Exception ex = null; 986 try 987 { 988 sub1.browse(); 989 } 990 catch (Exception e) 991 { 992 ex = e; 993 } 994 Assert.assertTrue("Unautz queue receiver throw wrong exception: " + ex, 995 ex instanceof javax.jms.JMSSecurityException ); 996 } 997 finally 998 { 999 try 1000 { 1001 sub1.close(); 1002 } 1003 catch (Exception ex) 1004 { 1005 } 1006 } 1007 } 1008 1009 public void runValidPreconfDurSub() throws Exception 1010 { 1011 TopicWorker sub1 = null; 1012 TopicWorker pub1 = null; 1013 try 1014 { 1015 drainTopic(); 1017 int ic = 5; 1018 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "DURABLE_NR", 0, ic); 1020 sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1); 1021 sub1.setDurable("john", "needle", "sub2"); 1022 Thread t1 = new Thread (sub1); 1023 t1.start(); 1024 sleep(2000); 1026 IntRangeMessageCreator c1 = new IntRangeMessageCreator("DURABLE_NR", 0); 1028 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic); 1029 pub1.connect(); 1030 pub1.publish(); 1031 Assert.assertEquals("Publisher did not publish correct number of messages " + pub1.getMessageHandled(), ic, 1032 pub1.getMessageHandled()); 1033 log.debug("Sleeping for " + ((ic * 100) / 60000) + " minutes"); 1035 sleep(ic * 100); 1036 Exception ex = sub1.getException(); 1037 if (ex != null) 1038 log.error("ValidPreconfDurSub got an exception: " + ex, ex); 1039 Assert.assertTrue("ValidPreconfDurSub did not work", ex == null); 1040 Assert.assertEquals("Subscriber did not get correct number of messages " + sub1.getMessageHandled(), ic, sub1 1041 .getMessageHandled()); 1042 t1.interrupt(); 1043 } 1044 finally 1045 { 1046 try 1047 { 1048 pub1.close(); 1049 } 1050 catch (Exception ex) 1051 { 1052 } 1053 try 1054 { 1055 sub1.unsubscribe(); 1058 sub1.close(); 1059 } 1060 catch (Exception ex) 1061 { 1062 } 1063 } 1064 } 1065 1066 public void runInvalidPreconfDurSub() throws Exception 1067 { 1068 TopicWorker sub1 = null; 1069 try 1070 { 1071 TEST_TOPIC = "topic/securedTopic"; 1073 int ic = 5; 1075 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "DURABLE_NR", 0, ic); 1077 sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1); 1078 sub1.setDurable("john", "needle", "sub3"); 1079 Thread t1 = new Thread (sub1); 1080 t1.start(); 1081 sleep(2000); 1083 Exception ex = sub1.getException(); 1084 Assert.assertTrue("InvalidPreconfDurSub did not get correct exception:" + ex, 1085 ex instanceof javax.jms.JMSSecurityException ); 1086 t1.interrupt(); 1087 } 1088 finally 1089 { 1090 try 1091 { 1092 sub1.close(); 1093 } 1094 catch (Exception ex) 1095 { 1096 } 1097 } 1098 } 1099 1100 public void runValidDynDurSub() throws Exception 1101 { 1102 TopicWorker sub1 = null; 1103 TopicWorker pub1 = null; 1104 try 1105 { 1106 drainTopic(); 1108 int ic = 5; 1109 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "DURABLE_NR", 0, ic); 1111 sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1); 1112 sub1.setDurable("dynsub", "dynsub", "sub4"); 1113 sub1.setClientID("myId"); 1114 Thread t1 = new Thread (sub1); 1115 t1.start(); 1116 sleep(2000); 1118 IntRangeMessageCreator c1 = new IntRangeMessageCreator("DURABLE_NR", 0); 1120 pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic); 1121 pub1.connect(); 1122 pub1.publish(); 1123 Assert.assertEquals("Publisher did not publish correct number of messages " + pub1.getMessageHandled(), ic, 1124 pub1.getMessageHandled()); 1125 log.debug("Sleeping for " + ((ic * 100) / 60000) + " minutes"); 1127 sleep(ic * 100); 1128 Exception ex = sub1.getException(); 1129 if (ex != null) 1130 log.error("ValidDynDurSub got an exception: " + ex, ex); 1131 Assert.assertTrue("ValidDynDurSub did not work", ex == null); 1132 Assert.assertEquals("Subscriber did not get correct number of messages " + sub1.getMessageHandled(), ic, sub1 1133 .getMessageHandled()); 1134 t1.interrupt(); 1135 } 1136 finally 1137 { 1138 try 1139 { 1140 pub1.close(); 1141 } 1142 catch (Exception ex) 1143 { 1144 } 1145 try 1146 { 1147 sub1.unsubscribe(); 1150 sub1.close(); 1151 } 1152 catch (Exception ex) 1153 { 1154 } 1155 } 1156 } 1157 1158 public void runInvalidDynDurSub() throws Exception 1159 { 1160 TopicWorker sub1 = null; 1161 try 1162 { 1163 TEST_TOPIC = "topic/securedTopic"; 1165 int ic = 5; 1167 IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message .class, "DURABLE_NR", 0, ic); 1169 sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1); 1170 sub1.setDurable("dynsub", "dynsub", "sub5"); 1171 sub1.setClientID("myId2"); 1172 Thread t1 = new Thread (sub1); 1173 t1.start(); 1174 sleep(2000); 1176 Exception ex = sub1.getException(); 1177 Assert.assertTrue("InvalidDynDurSub did not get correct exception:" + ex, 1178 ex instanceof javax.jms.JMSSecurityException ); 1179 t1.interrupt(); 1180 } 1181 finally 1182 { 1183 try 1184 { 1185 sub1.close(); 1186 } 1187 catch (Exception ex) 1188 { 1189 } 1190 } 1191 } 1192 1193 public static junit.framework.Test suite() throws Exception 1194 { 1195 TestSuite suite = new TestSuite(); 1196 1197 suite.addTest(new SecurityUnitTestCase("runLoginTest")); 1198 suite.addTest(new SecurityUnitTestCase("runLoginNoCred")); 1200 suite.addTest(new SecurityUnitTestCase("runLoginValidCred")); 1201 suite.addTest(new SecurityUnitTestCase("runLoginInvalidPwd")); 1202 suite.addTest(new SecurityUnitTestCase("runLoginInvalidCred")); 1203 suite.addTest(new SecurityUnitTestCase("runClientIDNormalTest")); 1205 suite.addTest(new SecurityUnitTestCase("runClientIDPreconfTest")); 1206 suite.addTest(new SecurityUnitTestCase("runClientIDSetTest")); 1207 suite.addTest(new SecurityUnitTestCase("runClientIDSetSteelPreconf")); 1208 suite.addTest(new SecurityUnitTestCase("runClientIDSetAfterInvoke")); 1209 suite.addTest(new SecurityUnitTestCase("runAuzValidTopicPublisher")); 1211 suite.addTest(new SecurityUnitTestCase("runAuzInvalidTopicPublisher")); 1212 suite.addTest(new SecurityUnitTestCase("runAuzValidTopicSubscriber")); 1213 suite.addTest(new SecurityUnitTestCase("runAuzInvalidTopicSubscriber")); 1214 suite.addTest(new SecurityUnitTestCase("runAuzValidQueueSender")); 1215 suite.addTest(new SecurityUnitTestCase("runAuzInvalidQueueSender")); 1216 suite.addTest(new SecurityUnitTestCase("runAuzValidQueueReceiver")); 1217 suite.addTest(new SecurityUnitTestCase("runAuzInvalidQueueReceiver")); 1218 suite.addTest(new SecurityUnitTestCase("runAuzValidTopicPublisherTransaction")); 1219 suite.addTest(new SecurityUnitTestCase("runAuzInvalidTopicPublisherTransaction")); 1220 suite.addTest(new SecurityUnitTestCase("runAuzValidTopicSubscriberTransaction")); 1221 suite.addTest(new SecurityUnitTestCase("runAuzInvalidTopicSubscriberTransaction")); 1222 suite.addTest(new SecurityUnitTestCase("runAuzValidQueueSenderTransaction")); 1223 suite.addTest(new SecurityUnitTestCase("runAuzInvalidQueueSenderTransaction")); 1224 suite.addTest(new SecurityUnitTestCase("runAuzValidQueueReceiverTransaction")); 1225 suite.addTest(new SecurityUnitTestCase("runAuzInvalidQueueReceiverTransaction")); 1226 suite.addTest(new SecurityUnitTestCase("runAuzValidQueueBrowser")); 1227 suite.addTest(new SecurityUnitTestCase("runAuzInvalidQueueBrowser")); 1228 suite.addTest(new SecurityUnitTestCase("runValidPreconfDurSub")); 1229 suite.addTest(new SecurityUnitTestCase("runInvalidPreconfDurSub")); 1230 suite.addTest(new SecurityUnitTestCase("runValidDynDurSub")); 1231 suite.addTest(new SecurityUnitTestCase("runInvalidDynDurSub")); 1232 Test wrapper = new JBossTestSetup(suite) 1235 { 1236 protected void setUp() throws Exception 1237 { 1238 super.setUp(); 1239 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 1240 deploy (loader.getResource("messaging/test-destinations-service.xml").toString()); 1241 } 1242 protected void tearDown() throws Exception 1243 { 1244 super.tearDown(); 1245 getServer().invoke(new ObjectName ("jboss.mq.destination:service=Queue,name=testQueue"), 1247 "removeAllMessages", new Object [0], new String [0]); 1248 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 1249 undeploy (loader.getResource("messaging/test-destinations-service.xml").toString()); 1250 } 1251 }; 1252 1253 return wrapper; 1254 } 1255 1256 public static void main(String [] args) 1257 { 1258 } 1259} | Popular Tags |