Unit Testing and the STS

I have written a RESTFul WS that eventually needs to call the SDL Web services to access the repository.  We currently employ the STS to get a token.  That token is stored in a cookie and is passed with subsequest requests from our custom UI to authenticate the user.

Issue we are trying to overcome is implementing unit testing on our code base.  The issue is that when I eventually make a call to the SDL services I get a response because it does not have the token.  

Has anyone else written code where you employ unit testing and how you overcome the issue of having to get a token?

Parents
  • Hi Patrick,

    We have in engineering a similar situation where we want to test our Web API endpoints.

    We do this through the same component that drives all authentication flows. The component is known as ServiceReferences and the implementation is in the .net assembly Trisoft.Utilities.ServiceReferences

    The internal flow combines active and passive profile.

    1. We use active profile and we issue a token through WS Trust. This step is different from the browser's flow because the code actively knows where to get the token from. This is very similar to issuing tokens for wcf proxies. The difference is that the request must be for a bearer token (browser) where for wcf services it is symmetric.
    2. We submit the token to the web site as the browser does. We replicated this step by looking in fiddler captures. We extract the cookies from this response.
    3. Inject the cookies on every request. If the cookie is valid then the server treats the request as authenticated.

    You can simulate multi-user scenarios by grabbing as many cookie sets as you want.

    The above sequence is executed from publication manager to show a preview. It authenticates and consumes endpoints both from Architect and Reach using the exact same principal.

    The options you have are

    • Implement the sequence your selves. We can provide some code samples and additional help. I believe you already have code that issues a token for WCF services. This means that you are very close for step 1. Step 2 is easy and then step 3 is relevant to your code structure.
    • Reference the Trisoft.Utilities.ServiceReferences assembly and all its dependencies. Using this assembly provides the implementation for steps 1 and 2 but there are two significant drawbacks.
      • This is an internal purpose assembly so it is eligible for a change without compatibility.
      • The assembly depends on other internal purpose assemblies that your code needs to inherit also. e.g. logging over nlog.

Reply
  • Hi Patrick,

    We have in engineering a similar situation where we want to test our Web API endpoints.

    We do this through the same component that drives all authentication flows. The component is known as ServiceReferences and the implementation is in the .net assembly Trisoft.Utilities.ServiceReferences

    The internal flow combines active and passive profile.

    1. We use active profile and we issue a token through WS Trust. This step is different from the browser's flow because the code actively knows where to get the token from. This is very similar to issuing tokens for wcf proxies. The difference is that the request must be for a bearer token (browser) where for wcf services it is symmetric.
    2. We submit the token to the web site as the browser does. We replicated this step by looking in fiddler captures. We extract the cookies from this response.
    3. Inject the cookies on every request. If the cookie is valid then the server treats the request as authenticated.

    You can simulate multi-user scenarios by grabbing as many cookie sets as you want.

    The above sequence is executed from publication manager to show a preview. It authenticates and consumes endpoints both from Architect and Reach using the exact same principal.

    The options you have are

    • Implement the sequence your selves. We can provide some code samples and additional help. I believe you already have code that issues a token for WCF services. This means that you are very close for step 1. Step 2 is easy and then step 3 is relevant to your code structure.
    • Reference the Trisoft.Utilities.ServiceReferences assembly and all its dependencies. Using this assembly provides the implementation for steps 1 and 2 but there are two significant drawbacks.
      • This is an internal purpose assembly so it is eligible for a change without compatibility.
      • The assembly depends on other internal purpose assemblies that your code needs to inherit also. e.g. logging over nlog.

Children
No Data