예제 #1
0
        public void TestBannedEmailIsHandledCorrectlyUsingMockedObjects()
        {
            Console.WriteLine("Before TestBannedEmailIsHandledCorrectlyUsingMockedOnbjects");
            Mockery mockery = new Mockery();
            IInputContext mockedInput = mockery.NewMock<IInputContext>();

            DnaCookie testCookie = new DnaCookie();
            testCookie.Value = TestUserAccounts.GetNormalUserAccount.Cookie; //"6042002|DotNetNormalUser|DotNetNormalUser|1273497514775|0|bf78fdd57a1f70faee630c07ba31674eab181a3f6c6f";
            testCookie.Name = "IDENTITY";
             
            DnaCookie testCookie2 = new DnaCookie();
            testCookie2.Value = TestUserAccounts.GetNormalUserAccount.SecureCookie; //"1eda650cb28e56156217427336049d0b8e164765";
            testCookie2.Name = "IDENTITY-HTTPS";
           
            //DnaCookie testCookie = new DnaCookie();
            //testCookie.Value = "THIS-IS-A-TEST-COOKIE-THAT-IS-LONGER-THAN-SIXTYFOUR-CHARACTURES-LONG";
            //testCookie.Name = "SSO2-UID";

            Stub.On(mockedInput).Method("GetCookie").With("IDENTITY").Will(Return.Value(testCookie));
            Stub.On(mockedInput).Method("GetCookie").With("IDENTITY-HTTPS").Will(Return.Value(testCookie2));
            Stub.On(mockedInput).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
            Stub.On(mockedInput).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));

            CreateMockedProfileConnection(mockery, mockedInput, 1063883681, "Fink", "TEST-TEST-TEST", "*****@*****.**", true);

            SetDefaultDiagnostics(mockery, mockedInput);

            CreateMockedSite(mockery, mockedInput, 1, "h2g2", "h2g2", true, "comment");
            // CreateMockedSite(mockery, mockedInput, 1, "h2g2", "h2g2", true, "comment");

            // Add the mocked datareader for getting the user info from the database.
            CreateMockedReaderForUserNotInDataBase(mockery, mockedInput);

            // Now mock the database reader for the two requests. The first needs to return true for email in banned list.
            CreateMockedReaderForEmailInBannedListCheck(mockery, mockedInput, 1, true);
            
            // Ok, create the user object and try to create the user.
            User testUser = new User(mockedInput);
            testUser.CreateUser();

            // The expect Once call on the IsEmailInBannedList procedure should indicate that the second call to the create method is using the
            // cookie banned list functionality.
            User testUser2 = new User(mockedInput);
            testUser2.CreateUser();

            // This will fail if the create user call got to check the data base more than once!
            mockery.VerifyAllExpectationsHaveBeenMet();
            Console.WriteLine("After TestBannedEmailIsHandledCorrectlyUsingMockedObjects");
        }
예제 #2
0
파일: User.cs 프로젝트: rocketeerbkw/DNA
        /// <summary>
        /// Initialises profile connection.
        /// </summary>
        /// <param name="cookie">Dna Cookie to login with</param>
        /// <param name="signInComponent">Initialised ProfileAPI</param>
        private bool InitialiseProfileAPI(DnaCookie cookie, ref IDnaIdentityWebServiceProxy signInComponent)
        {
            InputContext.Diagnostics.WriteTimedEventToLog("SSO", "Start");
            DateTime timer = DateTime.Now; 

            // Set the current user. If this returns false, it means the user was not signed in correctly
            string decodedCookie = cookie.Value;

            // Get a profile connection
            if (signInComponent.SignInSystemType == SignInSystem.Identity)
            {
                signInComponent.SetService(InputContext.CurrentSite.IdentityPolicy);
            }
            else
            {
                signInComponent.SetService(InputContext.CurrentSite.SSOService);
            }

            InputContext.Diagnostics.WriteTimedEventToLog("SSO","End");

            // Check to see if the service was set ok before calling any user functions
            if (!signInComponent.IsServiceSet)
            {
                InputContext.Diagnostics.WriteToLog("---** SignIn **---", "Service not set!!!");
                return false;
            }

            string secureCookie = "";
            if (InputContext.GetCookie("IDENTITY-HTTPS") != null)
            {
                secureCookie = InputContext.GetCookie("IDENTITY-HTTPS").Value;
            }

            bool userSet = signInComponent.TrySecureSetUserViaCookies(decodedCookie, secureCookie) || signInComponent.IsUserSignedIn;

            InputContext.IsSecureRequest = signInComponent.IsSecureRequest;
            InputContext.Diagnostics.WriteToLog("---** InputContext.IsSecureRequest **---", InputContext.IsSecureRequest.ToString());
            if (!userSet)
            {
                InputContext.Diagnostics.WriteToLog("---** SignIn **---", "Set user with cookie failed!!! - " + decodedCookie);
                if (secureCookie.Length > 0)
                {
                    InputContext.Diagnostics.WriteToLog("---** SignIn **---", "Set user with secure cookie failed!!! - " + secureCookie);
                }

                InputContext.Diagnostics.WriteToLog("---** SignIn **---", "Timing Info: "+signInComponent.GetLastTimingInfo());

                return false;
            }

            Statistics.AddIdentityCallDuration(TimeSpan.FromTicks(DateTime.Now.Ticks - timer.Ticks).Milliseconds);

            return true;
        }
예제 #3
0
        /// <summary>
        /// Initialises a new default user from a sso uid
        /// </summary>
        public void InitUserFromCookie(string identity, string identityHttps)
        {
            if (_identityCookie == null)
            {
                _identityCookie = new DnaCookie(new System.Web.HttpCookie("IDENTITY"));
                _identitySecureCookie = new DnaCookie(new System.Web.HttpCookie("IDENTITY-HTTPS"));
            }
            _identityCookie.Value = identity;
            _identitySecureCookie.Value = identityHttps;

            _viewingUser = new BBC.Dna.User(this);
            _viewingUser.CreateUser();
        }
예제 #4
0
        public void TestServiceWithNoEmailAttributeCreatesUsers()
        {
            Console.WriteLine("Before TestBannedUserCaughtEvenWithinvalidCookie");

            // Create the input context to run the requests in
            Mockery mockery = new Mockery();
            IInputContext mockedInput = mockery.NewMock<IInputContext>();

            // Create the invalid cookie. Invalid cookies are less or equal to 64 chars long
            DnaCookie cookie = new DnaCookie();
            cookie.Name = "SSO2-UID";
            cookie.Value = "VALID-COOKIE-ABCDEFGHIJKLMNOPQRRSTUVWXYZ-SSO-NORMAL-USER-ACCOUNT";

            // Stub the cookie to the context
			Stub.On(mockedInput).Method("GetCookie").With("SSO2-UID").Will(Return.Value(cookie));
			Stub.On(mockedInput).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
            Stub.On(mockedInput).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));

            // Now add the mocked profile connection
            CreateMockedProfileConnection(mockery, mockedInput, 106663681, "Fink", "TEST-TEST-TEST-NOEMAIL-ATTRIBUTE", "", false);

            SetDefaultDiagnostics(mockery, mockedInput);

            CreateMockedSite(mockery, mockedInput, 1, "h2g2", "h2g2", true, "comment");

            // Add the mocked datareader for getting the user info from the database.
            IDnaDataReader mockedNormalUserReader = mockery.NewMock<IDnaDataReader>();
            Stub.On(mockedNormalUserReader).Method("AddParameter").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedNormalUserReader).Method("Execute").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedNormalUserReader).Method("Dispose").Will(Return.Value(null));
            Stub.On(mockedNormalUserReader).Method("Read").Will(Return.Value(false));

            // Create an action list for the HasRows property
            IAction mockReaderResults = new MockedReaderResults(new bool[] { false, true, true });
            Stub.On(mockedNormalUserReader).GetProperty("HasRows").Will(mockReaderResults);

            // These both need to return the same results, so use the same mocked reader for both requests
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("fetchusersgroups").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("finduserfromid").Will(Return.Value(mockedNormalUserReader));
            //Stub.On(mockedInput).Method("CreateDnaDataReader").With("GetDnaUserIDFromSSOUserID").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("GetDnaUserIDFromIdentityUserID").Will(Return.Value(mockedNormalUserReader));
            
            // Create the mocked data reader for the createnewuserfromuserid call
            CreateMockedCreateUserDataReader(mockery, mockedInput, 106663681);

            // Mock the siteoption call for the checkusernameset option
            Stub.On(mockedInput).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));

            // Ok, create the user object and try to create the user.
            User testUser = new User(mockedInput);
            testUser.CreateUser();

            // This will fail if the create user call got to check the data base more than twice!
            mockery.VerifyAllExpectationsHaveBeenMet();
            Console.WriteLine("Before TestBannedUserCaughtEvenWithinvalidCookie");
        }
예제 #5
0
        public void TestBannedUserCaughtEvenWithinvalidCookie()
        {
            Console.WriteLine("Before TestBannedUserCaughtEvenWithinvalidCookie");

            // Create the input context to run the requests in
            Mockery mockery = new Mockery();
            IInputContext mockedInput = mockery.NewMock<IInputContext>();

            // Create the invalid cookie. Invalid cookies are less or equal to 64 chars long
            DnaCookie cookie = new DnaCookie();
            cookie.Name = "SSO2-UID";
            cookie.Value = "INVALID-COOKIE";

            // Stub the cookie to the context
			Stub.On(mockedInput).Method("GetCookie").With("SSO2-UID").Will(Return.Value(cookie));
			Stub.On(mockedInput).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
            Stub.On(mockedInput).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));

            // Now add the mocked profile connection
            CreateMockedProfileConnection(mockery, mockedInput, 106663681, "BadFink", "TEST-TEST-TEST-BANNED-USER", "*****@*****.**", true);

            // Set the diagnostics for the context
            SetDefaultDiagnostics(mockery, mockedInput);

            // Add the site for the context
            CreateMockedSite(mockery, mockedInput, 1, "h2g2", "h2g2", true, "comment");

            // Add the mocked datareader for getting the user info from the database.
            CreateMockedReaderForUserNotInDataBase(mockery, mockedInput);

            // Now mock the database reader for the two requests. The first needs to return true for email in banned list.
            CreateMockedReaderForEmailInBannedListCheck(mockery, mockedInput, 2, true);

            // Now create the banned user for the first time.
            User bannedUser = new User(mockedInput);
            bannedUser.CreateUser();

            // Now call the create method again. This should also check the database
            bannedUser.CreateUser();

            // This will fail if the create user call got to check the data base more than twice!
            mockery.VerifyAllExpectationsHaveBeenMet();
            Console.WriteLine("Before TestBannedUserCaughtEvenWithinvalidCookie");
        }
예제 #6
0
        public void TestNonBannedUserWithInvalidCookieGetsCreatedOk()
        {
            Console.WriteLine("Before TestNonBannedUserWithInvalidCookieGetsCreatedOk");
            Mockery mockery = new Mockery();
            IInputContext mockedInput = mockery.NewMock<IInputContext>();

            DnaCookie testCookie = new DnaCookie();
            testCookie.Value = "THIS-IS-A-TEST-COOKIE-THAT-IS-NOT-VALID";
            testCookie.Name = "SSO2-UID";
			Stub.On(mockedInput).Method("GetCookie").With("SSO2-UID").Will(Return.Value(testCookie));
			Stub.On(mockedInput).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
            Stub.On(mockedInput).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));

            CreateMockedProfileConnection(mockery, mockedInput, 1063883681, "Fink", "TEST-TEST-TEST", "*****@*****.**", true);

            SetDefaultDiagnostics(mockery, mockedInput);

            CreateMockedSite(mockery, mockedInput, 1, "h2g2", "h2g2", true, "comment");

            // Add the mocked datareader for getting the user info from the database.
            IDnaDataReader mockedNormalUserReader = mockery.NewMock<IDnaDataReader>();
            Stub.On(mockedNormalUserReader).Method("AddParameter").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedNormalUserReader).Method("Execute").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedNormalUserReader).Method("Dispose").Will(Return.Value(null));
            Stub.On(mockedNormalUserReader).Method("Read").Will(Return.Value(false));

            // Create an action list for the HasRows property
            IAction mockReaderResults = new MockedReaderResults(new bool[] { false, true, true });
            Stub.On(mockedNormalUserReader).GetProperty("HasRows").Will(mockReaderResults);

            // These both need to return the same results, so use the same mocked reader for both requests
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("fetchusersgroups").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("finduserfromid").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("GetDnaUserIDFromSSOUserID").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput).Method("CreateDnaDataReader").With("GetDnaUserIDFromIdentityUserID").Will(Return.Value(mockedNormalUserReader));

            // Mock the siteoption call for the checkusernameset option
            Stub.On(mockedInput).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));

            // Create the mocked data reader for the createnewuserfromuserid call
            CreateMockedCreateUserDataReader(mockery, mockedInput, 106663681);

            // Now mock the database reader for the two requests. The first needs to return true for email in banned list.
            CreateMockedReaderForEmailInBannedListCheck(mockery, mockedInput, 1, false);

            // Mock the siteoption call for the checkusernameset option
            Stub.On(mockedInput).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));

            // Ok, create the user object and try to create the user.
            User testUser = new User(mockedInput);
            testUser.CreateUser();

            // This will fail if the create user call got to check the data base more than once!
            mockery.VerifyAllExpectationsHaveBeenMet();
            Console.WriteLine("After TestNonBannedUserWithInvalidCookieGetsCreatedOk");
        }
예제 #7
0
        //See above - work with Mark H to understand what the test is for.
        public void TestNormalUserCanBeCreatedAfterABannedUserIsCaught()
        {
            Console.WriteLine("Before TestNormalUserCanBeCreatedAfterABannedUserIsCaught");
            
            // Start by creating two contexts. One for each request
            Mockery mockery = new Mockery();
            IInputContext mockedInput = mockery.NewMock<IInputContext>();
            IInputContext mockedInput2 = mockery.NewMock<IInputContext>();

            DnaCookie testBannedCookie = new DnaCookie();
            testBannedCookie.Value = TestUserAccounts.GetBannedUserAccount.Cookie; //"6042004|DotNetUserBanned|DotNetUserBanned|1273497847257|0|9d9ee980c4b831e419915b452b050f327862bba748ff";
            testBannedCookie.Name = "IDENTITY";

            DnaCookie testBannedCookie2 = new DnaCookie();
            testBannedCookie2.Value = TestUserAccounts.GetBannedUserAccount.SecureCookie; //"a684c1a5736f052c4acc1b35908f8dbad2e2ea0b";
            testBannedCookie2.Name = "IDENTITY-HTTPS";

            DnaCookie testNormalCookie = new DnaCookie();
            testNormalCookie.Value = TestUserAccounts.GetBannedUserAccount.Cookie; //"6042002|DotNetNormalUser|DotNetNormalUser|1273497514775|0|bf78fdd57a1f70faee630c07ba31674eab181a3f6c6f";
            testNormalCookie.Name = "IDENTITY";

            DnaCookie testNormalCookie2 = new DnaCookie();
            testNormalCookie2.Value = TestUserAccounts.GetBannedUserAccount.SecureCookie; // "1eda650cb28e56156217427336049d0b8e164765";
            testNormalCookie2.Name = "IDENTITY-HTTPS";

            // Now set the two test cookies. One for each user
            DnaCookie cookie1 = new DnaCookie();
            cookie1.Name = "SSO2-UID";
            cookie1.Value = "VALID-COOKIE-ABCDEFGHIJKLMNOPQRRSTUVWXYZ-SSO-BANNED-USER-ACCOUNT";

            DnaCookie cookie2 = new DnaCookie();
            cookie2.Name = "SSO2-UID";
            cookie2.Value = "VALID-COOKIE-ABCDEFGHIJKLMNOPQRRSTUVWXYZ-SSO-NORMAL-USER-ACCOUNT";

            // Stub the cookies to the contexts
            Stub.On(mockedInput).Method("GetCookie").With("IDENTITY").Will(Return.Value(testBannedCookie));
            Stub.On(mockedInput).Method("GetCookie").With("IDENTITY-HTTPS").Will(Return.Value(testBannedCookie2));

            Stub.On(mockedInput2).Method("GetCookie").With("IDENTITY").Will(Return.Value(testNormalCookie));
            Stub.On(mockedInput2).Method("GetCookie").With("IDENTITY-HTTPS").Will(Return.Value(testNormalCookie2));
            
            Stub.On(mockedInput).Method("GetCookie").With("SSO2-UID").Will(Return.Value(cookie1));
			Stub.On(mockedInput2).Method("GetCookie").With("SSO2-UID").Will(Return.Value(cookie2));
			Stub.On(mockedInput).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
			Stub.On(mockedInput2).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
            Stub.On(mockedInput).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));
            Stub.On(mockedInput2).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));

            // Now add the mocked profile connections
            CreateMockedProfileConnection(mockery, mockedInput, 106663681, "BadFink", "TEST-TEST-TEST-BANNED-USER", "*****@*****.**", true);
            IDnaIdentityWebServiceProxy mockedGoodProfile = CreateMockedProfileConnection(mockery, mockedInput2, 1063883681, "GoodFink", "TEST-TEST-TEST-NORMAL-USER", "*****@*****.**", true);

            // Create the mocked data reader for the createnewuserfromuserid call
            CreateMockedCreateUserDataReader(mockery, mockedInput2, 106663681);

            // Set the diagnostics for the contexts
            SetDefaultDiagnostics(mockery, mockedInput);
            SetDefaultDiagnostics(mockery, mockedInput2);

            // Add the site for the contexts
            CreateMockedSite(mockery, mockedInput, 1, "h2g2", "h2g2", true, "comment");
            CreateMockedSite(mockery, mockedInput2, 1, "h2g2", "h2g2", true, "comment");

            // Add the mocked datareader for getting the user info from the database.
            CreateMockedReaderForUserNotInDataBase(mockery, mockedInput);

            //CreateMockedReaderForUserNotInDataBase(mockery, mockedInput2);
            IDnaDataReader mockedNormalUserReader = mockery.NewMock<IDnaDataReader>();
            Stub.On(mockedNormalUserReader).Method("AddParameter").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedNormalUserReader).Method("Execute").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedNormalUserReader).Method("Dispose").Will(Return.Value(null));
            Stub.On(mockedNormalUserReader).Method("Read").Will(Return.Value(false));

            // Create an action list for the Read and HasRows method/property
            IAction mockReaderResults = new MockedReaderResults(new bool[] {false,true,true});
            Stub.On(mockedNormalUserReader).GetProperty("HasRows").Will(mockReaderResults);

            // These both need to return the same results, so use the same mocked reader for both requests
            Stub.On(mockedInput2).Method("CreateDnaDataReader").With("fetchusersgroups").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput2).Method("CreateDnaDataReader").With("finduserfromid").Will(Return.Value(mockedNormalUserReader));
            //Stub.On(mockedInput2).Method("CreateDnaDataReader").With("GetDnaUserIDFromSSOUserID").Will(Return.Value(mockedNormalUserReader));
            Stub.On(mockedInput2).Method("CreateDnaDataReader").With("GetDnaUserIDFromIdentityUserID").Will(Return.Value(mockedNormalUserReader));
            
            // Now mock the database reader for the two requests. The first needs to return true for email in banned list.
            CreateMockedReaderForEmailInBannedListCheck(mockery, mockedInput, 1, true);
            CreateMockedReaderForEmailInBannedListCheck(mockery, mockedInput2, 1, false);

            // Mock the siteoption call for the checkusernameset option
            Stub.On(mockedInput).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));
            Stub.On(mockedInput2).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));

            // Now do the test.
            // 1. Test banned user is caught and not created in the database
            // 2. Test that a normal user can be created after the banned user
            // 3. Test to make sure the banned user is caught by the banned cookie list with out calling the database.

            // Banned user first call. This should check the database and then add their cookie to the list
            User bannedUser = new User(mockedInput);
            bannedUser.CreateUser();

            // Normal user. This should check the database and return false for being in the banned list. This should create the user in the database.
            User normalUser = new User(mockedInput2);
            normalUser.CreateUser();

            // Banned user second call. This should not call the database, but be caught by the cookie list.
            bannedUser.CreateUser();

            // This will fail if the create user call got to check the data base more than once for both users!
            mockery.VerifyAllExpectationsHaveBeenMet();
            Console.WriteLine("After TestNormalUserCanBeCreatedAfterABannedUserIsCaught");
        }
예제 #8
0
        /// <summary>
        /// Helper method for creating a mocked profile connection object.
        /// This method defaults to setting the user to be logged in, and having the service set
        /// </summary>
        /// <param name="mockedInput">The context you want to add the mocked connection to</param>
        /// <param name="userID">The users ID</param>
        /// <param name="loginName">The user login name</param>
        /// <param name="bbcUID">The user BBCUID</param>
        /// <param name="email">The users email</param>
        /// <param name="ssoUID">The SSO-UID cookie value for the user</param>
        /// <param name="serviceHasEmail">A flag to state whether or not the service supports emails</param>
        /// <returns>The new mocked profile connection</returns>
        public static IDnaIdentityWebServiceProxy CreateMockedProfileConnection(IInputContext mockedInput, int userID, string loginName, string bbcUID, string ssoUID, string email, bool serviceHasEmail)
        {
            // Create and initialise the mocked profile connection
            IDnaIdentityWebServiceProxy mockedProfile = _mockery.NewMock<IDnaIdentityWebServiceProxy>();
            Stub.On(mockedProfile).Method("SetService").Will(Return.Value(null));
            Stub.On(mockedProfile).GetProperty("IsServiceSet").Will(Return.Value(true));
            Stub.On(mockedProfile).GetProperty("IsSecureRequest").Will(Return.Value(true));

            //Stub.On(mockedProfile).Method("TrySetUserViaCookie").Will(Return.Value(true));
            //Stub.On(mockedProfile).Method("TrySetUserViaCookieAndUserName").Will(Return.Value(true));
            Stub.On(mockedProfile).Method("TrySecureSetUserViaCookies").Will(Return.Value(true));

            Stub.On(mockedProfile).GetProperty("IsUserLoggedIn").Will(Return.Value(true));
            Stub.On(mockedProfile).GetProperty("IsUserSignedIn").Will(Return.Value(true));
            
            Stub.On(mockedProfile).GetProperty("UserID").Will(Return.Value(userID.ToString()));
            Stub.On(mockedProfile).GetProperty("LoginName").Will(Return.Value(loginName));

            Stub.On(mockedProfile).Method("DoesAttributeExistForService").With("h2g2", "email").Will(Return.Value(serviceHasEmail));
            Stub.On(mockedProfile).Method("GetUserAttribute").With("email").Will(Return.Value(email));

            Stub.On(mockedProfile).Method("DoesAttributeExistForService").With("h2g2", "legacy_user_id").Will(Return.Value(false));
            Stub.On(mockedProfile).Method("GetUserAttribute").With("legacy_user_id").Will(Return.Value(""));

            Stub.On(mockedProfile).Method("DoesAttributeExistForService").With("h2g2", "firstname").Will(Return.Value(false));
            Stub.On(mockedProfile).Method("DoesAttributeExistForService").With("h2g2", "lastname").Will(Return.Value(false));
            Stub.On(mockedProfile).Method("DoesAttributeExistForService").With("h2g2", "displayname").Will(Return.Value(false));
            Stub.On(mockedProfile).Method("DoesAttributeExistForService").With("h2g2", "lastupdated").Will(Return.Value(false));


            Stub.On(mockedProfile).Method("CloseConnections").Will(Return.Value(null));
            Stub.On(mockedProfile).GetProperty("GetCookieValue").Will(Return.Value(""));
            Stub.On(mockedProfile).GetProperty("SignInSystemType").Will(Return.Value(SignInSystem.Identity));

            Stub.On(mockedInput).GetProperty("IsSecureRequest").Will(Return.Value(true));
            Stub.On(mockedInput).SetProperty("IsSecureRequest").To(true);

            Stub.On(mockedInput).GetProperty("IpAddress").Will(Return.Value(""));
            Stub.On(mockedInput).GetProperty("BBCUid").Will(Return.Value(Guid.Empty));

            // Create the cookies
            DnaCookie cookie = new DnaCookie();
            cookie.Name = "SSO2-UID";
            cookie.Value = ssoUID;

            DnaCookie bbcuidcookie = new DnaCookie();
            cookie.Name = "BBC-UID";
            cookie.Value = bbcUID;

            // Stub the cookie to the context
            Stub.On(mockedInput).Method("GetCookie").With("SSO2-UID").Will(Return.Value(cookie));
            Stub.On(mockedInput).Method("GetCookie").With("H2G2DEBUG").Will(Return.Value(null));
            Stub.On(mockedInput).Method("GetCookie").With("BBC-UID").Will(Return.Value(bbcuidcookie));
            Stub.On(mockedInput).Method("GetCookie").With("IDENTITY-USERNAME").Will(Return.Value(new DnaCookie(new System.Web.HttpCookie("IDENTITY-USERNAME", loginName + "|huhi|7907980"))));
            Stub.On(mockedInput).Method("GetParamIntOrZero").With("s_sync", "User's details must be synchronised with the data in SSO.").Will(Return.Value(0));

            Stub.On(mockedInput).Method("GetCookie").With("IDENTITY").Will(Return.Value(new DnaCookie(new System.Web.HttpCookie("IDENTITY", loginName + "|huhi|7907980"))));
            Stub.On(mockedInput).Method("GetCookie").With("IDENTITY-HTTPS").Will(Return.Value(new DnaCookie(new System.Web.HttpCookie("IDENTITY-HTTPS", ""))));

            // Add the mocked profile to the first context
            Stub.On(mockedInput).GetProperty("GetCurrentSignInObject").Will(Return.Value(mockedProfile));

            // Mock the siteoption call for the UseSiteSuffix and AutoGeneratedNames option
            Stub.On(mockedInput).Method("GetSiteOptionValueBool").With("User", "UseSiteSuffix").Will(Return.Value(false));
            Stub.On(mockedInput).Method("GetSiteOptionValueBool").With("User", "AutoGeneratedNames").Will(Return.Value(false));

            Stub.On(mockedInput).Method("UrlEscape").WithAnyArguments().Will(Return.Value("Escaped Email"));

            return mockedProfile;
        }