public async Task <string> CreateUserSession(CreateSessionRequest request)
        {
            if (request == null)
            {
                request = new CreateSessionRequest();
            }

            //Create new Session here
            var dfcUserSession = _sessionClient.NewSession();

            dfcUserSession.Origin = Origin.MatchSkills;
            _sessionClient.CreateCookie(dfcUserSession, true);

            var userSession = new UserSession()
            {
                UserSessionId       = dfcUserSession.SessionId,
                PartitionKey        = dfcUserSession.PartitionKey,
                Salt                = dfcUserSession.Salt,
                CurrentPage         = request.CurrentPage,
                PreviousPage        = request.PreviousPage,
                UserHasWorkedBefore = request.UserHasWorkedBefore,
                RouteIncludesDysac  = request.RouteIncludesDysac,
                LastUpdatedUtc      = DateTime.UtcNow,
                SessionCreatedDate  = dfcUserSession.CreatedDate
            };

            var result = await _cosmosService.CreateItemAsync(userSession, CosmosCollection.Session);

            return(result.IsSuccessStatusCode ? userSession.PrimaryKey : null);
        }
        public void CreateCookieThrowsExceptionWhenSessionNotValid()
        {
            // Arrange
            A.CallTo(() => sessionIdGenerator.ValidateSessionId(A <DfcUserSession> .Ignored)).Returns(false);
            var userSession = new DfcUserSession();

            // Act
            Assert.Throws <ArgumentException>(() => sessionClient.CreateCookie(userSession, true));

            // Assert
            A.CallTo(() => logger.Log(LogLevel.Warning, 0, A <FormattedLogValues> .Ignored, A <Exception> .Ignored, A <Func <object, Exception, string> > .Ignored)).MustHaveHappenedOnceExactly();
        }
Beispiel #3
0
        public void CreateCookie(string sessionIdAndPartionKey)
        {
            var sessionIdAndPartitionKeyDetails = GetSessionAndPartitionKey(sessionIdAndPartionKey);
            var dfcUserSession = new DfcUserSession()
            {
                Salt = "ncs", PartitionKey = sessionIdAndPartitionKeyDetails.Item1, SessionId = sessionIdAndPartitionKeyDetails.Item2
            };

            sessionServiceClient.CreateCookie(dfcUserSession, false);
        }
Beispiel #4
0
        public void CreateCookieAddsToResponseCookies()
        {
            // Arrange
            var session = sessionClient.NewSession();

            contextAccessor.HttpContext = new DefaultHttpContext();

            // Act
            sessionClient.CreateCookie(session, true);

            var headers         = contextAccessor.HttpContext.Response.Headers;
            var setCookieHeader = headers["Set-Cookie"][0];

            Assert.Contains(DefaultSessionName, setCookieHeader, StringComparison.OrdinalIgnoreCase);
            Assert.Contains(session.SessionId, setCookieHeader, StringComparison.OrdinalIgnoreCase);
        }
Beispiel #5
0
            public void Init()
            {
                _cosmosSettings = Options.Create(new CosmosSettings()
                {
                    ApiUrl                 = "https://test-account-not-real.documents.azure.com:443/",
                    ApiKey                 = "VGhpcyBpcyBteSB0ZXN0",
                    DatabaseName           = "DatabaseName",
                    UserSessionsCollection = "UserSessions"
                });
                var dummySession = new DfcUserSession()
                {
                    SessionId = "partitionkey-sessionid"
                };

                _sessionClient.NewSession().Returns(dummySession);
                _sessionClient.CreateCookie(Arg.Any <DfcUserSession>(), true);
                _client        = new Mock <CosmosClient>();
                _sessionConfig = Options.Create(new SessionConfig()
                {
                    Salt = "ThisIsASalt", ApplicationName = "matchskills"
                });
            }
Beispiel #6
0
        private DysacServiceResponse  CreateDysacServiceResponse(AssessmentShortResponse response, Origin creationOrigin, HttpStatusCode statusCode)
        {
            var dysacServiceResponse = new DysacServiceResponse();

            if (response != null && !string.IsNullOrEmpty(response.SessionId))
            {
                dysacServiceResponse.ResponseCode = DysacReturnCode.Ok;
                var userSession = new DfcUserSession()
                {
                    CreatedDate  = DateTime.Now,
                    PartitionKey = response.PartitionKey,
                    Salt         = response.Salt,
                    SessionId    = response.SessionId,
                    Origin       = creationOrigin
                };
                _sessionClient.CreateCookie(userSession, false);
            }
            else
            {
                throw new DysacException("No session. Error Code " + statusCode);
            }

            return(dysacServiceResponse);
        }
        public void CreateCookie()
        {
            sessionService.CreateCookie("p1-s1");

            A.CallTo(() => fakeSessionClient.CreateCookie(A <DfcUserSession> .That.Matches(x => x.PartitionKey == "p1" && x.SessionId == "s1"), false)).MustHaveHappenedOnceExactly();
        }