4 Replies Latest reply on Mar 26, 2008 12:38 PM by Wim Vandenhaute

    Using JSFUnit to test 2 communicating webapps

    Wim Vandenhaute Newbie

      I am trying to use JSFUnit on 2 webapps simultaneouly.

      The scenario is like this :

      The first webapp submits a log in action, which redirects to a second webapp, the authentication webapp.
      This one handles all authn and then redirects back to the original webapp with the auth credentials ( Its a saml request and response that are being communicated between those 2 ).

      What would be the preferred way to use jsf unit on the 'first' webapp ?
      All that should be tested, needs to have the user being logged in so the nicest way would being able to actually submit my saml request to the authentication webapp, use jsfunit also on the authentication webapp and return with a saml response to the first webapp, doing further tests on all pages.

      Is such a scenario possible with JSFUnit ? Being we have 2 seperate war's here which need to communicate ... .

      Or should I look further on emulating the saml response containing the authn assertions getting send to a servlet in my 'first' webapp.

      Regards,
      W.

        • 1. Re: Using JSFUnit to test 2 communicating webapps
          Stan Silvert Master

          If the client uses the same jsessionid for both webapps then there will be no problem.

          Otherwise, you will have a similar problem as the one described in this thread:
          http://www.jboss.com/index.html?module=bb&op=viewtopic&t=131988

          You might be able to use the solution I proposed in that thread, but clearly we need more research into this kind of scenario.

          Stan

          • 2. Re: Using JSFUnit to test 2 communicating webapps
            Wim Vandenhaute Newbie

            Hey Stan,

            I solved it by emulating my authentication webapp with a single servlet.
            This servlet receives the authn request, authenticates the user and sends back the authn response. As this is al done within the same session I can continue further as a logged in user.

            One thing I have not found out yet is if it is possible to run more then 1 test under the same session. I will have to look further on how to handle that.

            Thanks for the quick reply,
            W.

            • 3. Re: Using JSFUnit to test 2 communicating webapps
              Stan Silvert Master

              Great! If you have time would you be willing to share your experience on our wiki? Maybe you could add/update or link from here:
              http://wiki.jboss.org/wiki/JSFUnitTestingSecurePages

              Regarding more than one test under the same session. You can certainly run more than one test:

              public class JSFUnitTest extends org.apache.cactus.ServletTestCase {
               public void testFoo() throws IOException, SAXException {
               // foo test
               }
              
               public void testBar() throws IOException, SAXException {
               // bar test
               }
              }


              What you can not do is have more than one JSFClientSession active at the same time:
              public class JSFUnitTest extends org.apache.cactus.ServletTestCase {
               public void testFoo() throws IOException, SAXException {
               JSFClientSession client1 = new JSFClientSession("/foo.jsf");
               JSFClientSession client2 = new JSFClientSession("/bar.jsf");
               client2.submit(); // this works
               client1.submit(); // this won't work, but it can be fixed in the future
               }
              
              }


              To see why, look at this wiki: http://wiki.jboss.org/wiki/JSFUnitSessionAndThreads

              Stan

              • 4. Re: Using JSFUnit to test 2 communicating webapps
                Wim Vandenhaute Newbie

                Hey Stan,

                Well I dont know if my solution is actually quite that valuable to add it to the wiki. From a JSFUnit point of view I only redirect to a certain URL, a filter is activated that sends out a saml request to the servlet I added.
                This one picks it up, authenticates the user to the container and sends a saml response to a second servlet, which in turn then redirects to the orignal URL ( where the filter was activated on ).

                So basically I dont post to my second webapp but to the local servlet which handles the authentication.

                But if you think it will give added value, sure, I'll add some documentation on my approach.

                As for the multiple tests, first I was looking for a way to re-use my authenticated session in multiple tests as at the moment a new session was allways created. But actually in the test flows I will implement I will probably have no need for that. To achieve that I probably just have to re-use the client and server session I used during authentication right ?

                Kind regards,
                W.