public void ToUid_WhenReal_ShouldReturnTheRightUid()
        {
            // Configure environment
            MnoHelper.Environment = "production";
            MnoHelper.Sso.CreationMode = "real";

            // Build user
            var samlResp = new SsoResponseStub();
            var user = new User(samlResp);

            Assert.AreEqual(user.Uid, user.ToUid());
        }
        public void ItShouldExtractTheRightAttributesFromTheSamlResponse()
        {
            var samlResp = new SsoResponseStub();
            var att = samlResp.GetAttributes();
            var user = new User(samlResp);

            Assert.AreEqual(att["mno_session"], user.SsoSession);
            Assert.AreEqual(DateTime.Parse(att["mno_session_recheck"]), user.SsoSessionRecheck);
            Assert.AreEqual(att["group_uid"], user.GroupUid);
            Assert.AreEqual(att["group_role"], user.GroupRole);
            Assert.AreEqual(att["uid"], user.Uid);
            Assert.AreEqual(att["virtual_uid"], user.VirtualUid);
            Assert.AreEqual(att["email"], user.Email);
            Assert.AreEqual(att["virtual_email"], user.VirtualEmail);
            Assert.AreEqual(att["name"], user.FirstName);
            Assert.AreEqual(att["surname"], user.LastName);
            Assert.AreEqual(att["country"], user.Country);
            Assert.AreEqual(att["company_name"], user.CompanyName);
        }
        public void Sso_SetSession_ItShouldSetTheUserInSession()
        {
            MnoHelper.Environment = "production";

            // Build context
            var samlResp = new SsoResponseStub();
            var att = samlResp.GetAttributes();
            var user = new User(samlResp);
            var session = Helpers.FakeHttpSessionState();
            MnoHelper.Sso.SetSession(session, user);

            // Decrypt session
            var enc = System.Text.Encoding.UTF8;
            var json = enc.GetString(Convert.FromBase64String(session["maestrano"].ToString()));
            var mnoObj = JObject.Parse(json);

            Assert.AreEqual(user.SsoSession, mnoObj.Value<String>("session"));
            Assert.AreEqual(user.Uid, mnoObj.Value<String>("uid"));
            Assert.AreEqual(user.GroupUid, mnoObj.Value<String>("group_uid"));
            Assert.AreEqual(user.SsoSessionRecheck, mnoObj.Value<DateTime>("session_recheck"));
        }
        public void Sso_ClearSession_ItShouldDeleteTheMaestranoSession()
        {
            MnoHelper.Environment = "production";

            // Build context
            var samlResp = new SsoResponseStub();
            var att = samlResp.GetAttributes();
            var user = new User(samlResp);
            var session = Helpers.FakeHttpSessionState();
            MnoHelper.Sso.SetSession(session, user);

            // Test
            MnoHelper.Sso.ClearSession(session);
            Assert.IsNull(session["maestrano"]);
        }
Example #5
0
 /// <summary>
 /// Set the maestrano user in session
 /// </summary>
 public void SetSession(HttpSessionState httpSessionObj, User user)
 {
     var mnoSession = new Session(httpSessionObj, user);
     mnoSession.Save();
 }
Example #6
0
        /// <summary>
        /// Scope a User to a specific configuration preset
        /// </summary>
        /// <param name="presetName"></param>
        /// <returns></returns>
        public static User With(string presetName = "maestrano")
        {
            User scopedUser = new User();
            scopedUser.presetName = presetName;

            return scopedUser;
        }
Example #7
0
 /// <summary>
 /// Set the maestrano user in session
 /// </summary>
 public void SetSession(HttpSessionState httpSessionObj, User user)
 {
     var mnoSession = Session.With(presetName).New(httpSessionObj, user);
     mnoSession.Save();
 }
Example #8
0
 /// <summary>
 /// Contructor retrieving maestrano session from user
 /// </summary>
 /// <param name="httpSessionObj"></param>
 /// <param name="user"></param>
 public Session(HttpSessionState httpSessionObj, User user)
 {
     this.New(httpSessionObj, user);
 }
Example #9
0
        /// <summary>
        /// Initializer retrieving maestrano session from user
        /// </summary>
        /// <param name="httpSessionObj"></param>
        /// <param name="user"></param>
        public Session New(HttpSessionStateBase httpSessionObj, User user)
        {
            HttpSession = httpSessionObj;

            if (user != null)
            {
                Uid = user.Uid;
                GroupUid = user.GroupUid;
                SessionToken = user.SsoSession;
                Recheck = user.SsoSessionRecheck;
            }

            return this;
        }
Example #10
0
 /// <summary>
 /// Initialize the Session
 /// </summary>
 /// <returns></returns>
 public Session New(HttpSessionState httpSessionObj, User user)
 {
     return this.New(new HttpSessionStateWrapper(httpSessionObj),user);
 }
        public void ItContructsAnInstanceFromHttpSessionStateObjectAndSsoUser()
        {
            // Http context
            Helpers.injectMnoSession();
            var httpSession = Helpers.FakeHttpSessionState();

            // User
            var samlResp = new SsoResponseStub();
            var user = new User(samlResp);

            Session mnoSession = new Session(httpSession, user);

            Assert.AreEqual(httpSession, mnoSession.HttpSession);
            Assert.AreEqual(user.Uid, mnoSession.Uid);
            Assert.AreEqual(user.GroupUid, mnoSession.GroupUid);
            Assert.AreEqual(user.SsoSession, mnoSession.SessionToken);
            Assert.AreEqual(user.SsoSessionRecheck, mnoSession.Recheck);
        }