Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I've been testing a RESTful webservice for the last little while using SoapUI. It's worked great until this week where a requirement was added that the web service must use kerberos authentication, which SoapUI does not seem to be able to handle.

Although I plan on getting my regression test completely automated using .NET, I still have a little bit more to learn before that becomes a viable option.

I've been spending a little bit of time with wfetch although was hoping that I could find a way to queue up requests or run them in order (I know that I may not be able to have my cake and eat it too).

Any recommendations?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Kerberos authentication can be really, really narky. What I found to solve the "run test as user x in .net" problem I needed to perform a two step process.

Step 1: Fire up the process I want to test as the alternate user.
Step 2: Use impersonation on the call to allow my test harness to access the process from the other user.

This was done for IE in WatiN, but I am guessing that the code will be similar, just calling your chosen test exe.

using System;
using System.Configuration;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Security;
using System.Net;
using System.Security.Principal;
using System.Reflection;
using System.IO;


 public static void SetAlternateUser(string userName, string password, string domain)
    {
        // thread safe singleton code
        lock (threadSafeLock)
        {
            if (_ie == null)
            {
                StartIE();
            }

            _ie.Close();
            _ie = null;


            // fill the NetworkCredeitials object that we use for impersonation
            if (string.IsNullOrEmpty(domain))
            {
                alternateUserCredentials = new NetworkCredential(userName, password);
            }
            else
            {
                alternateUserCredentials = new NetworkCredential(userName, password, domain);
            }

            // Prepare to launch
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UserName = userName;
            psi.Password = SecurePassword(password);
            if (!string.IsNullOrEmpty(domain))
            {
                psi.Domain = domain;
            }
            psi.UseShellExecute = false;
            psi.LoadUserProfile = true;
            psi.FileName = "c:\\Program Files\\Internet Explorer\\iexplore.exe";
            psi.Arguments = "about:blank";


            // launch
            Process proc = new Process();
            proc.StartInfo = psi;
            proc.Start();

            // Time to become an imposter
            hToken = IntPtr.Zero;
            hTokenDuplicate = IntPtr.Zero;

            if (Win32.LogonUser(alternateUserCredentials.UserName, alternateUserCredentials.Domain, alternateUserCredentials.Password, 2 /*LOGON32_LOGON_INTERACTIVE*/, 0 /*LOGON32_PROVIDER_DEFAULT*/, out hToken))
            {
                if (Win32.DuplicateToken(hToken, 2, out hTokenDuplicate))
                {
                    windowsIdentity = new WindowsIdentity(hTokenDuplicate);
                    impersonationContext = windowsIdentity.Impersonate();
                    System.Threading.Thread.Sleep(1000);

                    _ie = IE.AttachToIE(Find.ByUrl("about:blank"));

                }
            }
        }
    }
share|improve this answer
    
Is "narky" a technical term? I'm unfamiliar with it. ;-) –  TristaanOgre Jun 30 '11 at 17:05
    
Cool. This looks helpful. I probably won't get around to trying it until this weekend though. –  Lyndon Vrooman Jun 30 '11 at 18:45
    
Although I see a lot of potential for it in the future, this doens't seem to help me out as I am attempting to impersonate myself. the main problem being that IE and soapUI don't seem to authenticate properly. –  Lyndon Vrooman Jul 7 '11 at 3:52
    
Ended up doing some more work with this, and never could get it to work with SoapUI, but I did find that this worked well with a similar tool that we ended up putting together for testing. –  Lyndon Vrooman Jan 3 '12 at 11:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.