Пример #1
0
        public void Friend_Request_Should_Match_Target_User_Culture()
        {
            this.PrepareSecondLanguage();
            int    userId1, userId2, fileId1, fileId2;
            string userName1, userName2;

            this.CreateNewUser(out userId1, out userName1, out fileId1);
            this.CreateNewUser(out userId2, out userName2, out fileId2);

            this.UpdateUserProfile(userId1, UserProfile.USERPROFILE_PreferredLocale, FirstLanguage);
            this.UpdateUserProfile(userId2, UserProfile.USERPROFILE_PreferredLocale, SecondLanguage);
            WebApiTestHelper.ClearHostCache();

            var connector = WebApiTestHelper.LoginUser(userName1);

            connector.PostJson("API/MemberDirectory/MemberDirectory/AddFriend", new
            {
                friendId = userId2,
            }, this.GetRequestHeaders());

            var notificationTitle = this.GetNotificationTitle(userId1);

            // the notification should use french language: testuser8836 veut être amis avec vous
            Assert.AreEqual($"{userName1} veut être amis", notificationTitle);
        }
Пример #2
0
        public void ValidatingFailureWhenUsingNonExistingMoniker()
        {
            //Arrange
            const string query1 =
                @"SELECT TOP(1) TabModuleId FROM {objectQualifier}TabModules
	                WHERE TabId IN (SELECT TabId FROM {objectQualifier}Tabs WHERE TabName='Activity Feed')
	                  AND ModuleTitle='Journal';"    ;
            var tabModuleId = DatabaseHelper.ExecuteScalar <int>(query1);

            Assert.Greater(tabModuleId, 0);

            // These will set a moniker for the Activity Feed module of the user profile
            DatabaseHelper.ExecuteNonQuery(@"EXEC {objectQualifier}DeleteTabModuleSetting " + tabModuleId + @", 'Moniker'");
            WebApiTestHelper.ClearHostCache();

            // Act
            var token = GetAuthorizationTokenFor(_hostName, _hostPass);

            SetAuthHeaderToken(token.AccessToken);
            SetMonikerHeader("myjournal");
            var postItem = new { ProfileId = 1, GroupId = -1, RowIndex = 0, MaxRows = 1 };
            var result   = _httpClient.PostAsJsonAsync(
                "/API/Journal/Services/GetListForProfile", postItem).Result;
            var content = result.Content.ReadAsStringAsync().Result;

            LogText(@"content => " + content);
            Assert.AreEqual(HttpStatusCode.Unauthorized, result.StatusCode);
        }
Пример #3
0
        public void ExtendingTokenWithinLastHourExtendsUpToRenewalExpiry()
        {
            var     token1    = GetAuthorizationTokenFor(_hostName, _hostPass);
            var     parts     = token1.AccessToken.Split('.');
            var     decoded   = DecodeBase64(parts[1]);
            dynamic claims    = JsonConvert.DeserializeObject(decoded);
            string  sessionId = claims.sid;
            var     query     = "UPDATE {objectQualifier}JsonWebTokens SET RenewalExpiry=" +
                                $"'{DateTime.UtcNow.AddMinutes(30).ToString("yyyy-MM-dd HH:mm:ss")}' WHERE TokenId='{sessionId}';";

            DatabaseHelper.ExecuteNonQuery(query);
            WebApiTestHelper.ClearHostCache();

            var token2 = RenewAuthorizationToken(token1);

            parts   = token2.AccessToken.Split('.');
            decoded = DecodeBase64(parts[1]);
            claims  = JsonConvert.DeserializeObject(decoded);
            long claimExpiry   = claims.exp;
            var  expiryInToken = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(claimExpiry);

            Assert.Less(DateTime.UtcNow, expiryInToken);
            Assert.LessOrEqual(expiryInToken, DateTime.UtcNow.AddMinutes(31)); // appears the library rounds the time

            var record        = DatabaseHelper.GetRecordById("JsonWebTokens", "TokenId", sessionId);
            var accessExpiry  = (DateTime)record["TokenExpiry"];
            var renewalExpiry = (DateTime)record["RenewalExpiry"];

            Assert.AreEqual(accessExpiry, renewalExpiry);
            Assert.Less(DateTime.UtcNow, renewalExpiry);
            Assert.LessOrEqual(renewalExpiry, DateTime.UtcNow.AddMinutes(31));
            Assert.AreEqual(accessExpiry, expiryInToken);
        }
 public static void DisableAppStartDelay(bool clearCache = true)
 {
     DatabaseHelper.ExecuteStoredProcedure("UpdateHostSetting", "SchedulerdelayAtAppStart", "0", false, 1);
     if (clearCache)
     {
         WebApiTestHelper.ClearHostCache();
     }
 }
 public static void EnableScheduler(string schedulerName, bool clearCache = false)
 {
     var query = string.Format(
         "UPDATE {{objectQualifier}}Schedule SET Enabled=1 WHERE FriendlyName = '{0}';", schedulerName);
     DatabaseHelper.ExecuteNonQuery(query);
     if (clearCache)
     {
         WebApiTestHelper.ClearHostCache();
     }
 }
 public static void SetSchedulingMode(SchedulingMode mode, bool clearCache = true)
 {
     var current = GetSchedulingMode();
     if (current != mode)
     {
         DatabaseHelper.ExecuteStoredProcedure("UpdateHostSetting", "SchedulerMode", mode.ToString("D"), false, 1);
         if (clearCache)
         {
             WebApiTestHelper.ClearHostCache(); // must clear the site Cache afterwards
         }
     }
 }
Пример #7
0
        /// <summary>
        /// Sets a portal setting value, adding or updating the setting as required
        /// </summary>
        /// <param name="settingName">The name of the setting</param>
        /// <param name="settingValue">The value of the setting</param>
        /// <param name="portalId">The optional PortalId, default to 0</param>
        /// <param name="isSecure">This flag specifies whether the value is encrypted or not, defaults to false.</param>
        public static void SetPortalSetting(string settingName, string settingValue, int portalId = 0, bool isSecure = false)
        {
            var query = string.Format(@"MERGE INTO {{objectQualifier}}PortalSettings s
                    USING (SELECT {2} PortalId, '{0}' SettingName, '{1}' SettingValue, {3} Sec) AS v
                    ON s.SettingName = v.SettingName
                    WHEN MATCHED THEN UPDATE SET s.SettingValue = v.SettingValue, SettingIsSecure = v.Sec
                    WHEN NOT MATCHED THEN INSERT (PortalId, SettingName, SettingValue, SettingIsSecure)
				                          VALUES (v.PortalId, v.SettingName, v.SettingValue, v.Sec);"                ,
                                      settingName, settingValue, portalId, isSecure ? "1" : "0");

            DatabaseHelper.ExecuteNonQuery(query);
            WebApiTestHelper.ClearHostCache();
        }
Пример #8
0
        private static int CreateRole(string roleName, string roleDescription, int portalId = 0)
        {
            var fileContent  = SqlScripts.SingleRoleCreation;
            var masterScript = new StringBuilder(fileContent)
                               .Replace(PortalIdMarker, portalId.ToString(CultureInfo.InvariantCulture))
                               .Replace("{objectQualifier}", AppConfigHelper.ObjectQualifier)
                               .ToString();

            var script = new StringBuilder(masterScript)
                         .Replace(RoleNameMarker, roleName.Replace("'", "''"))
                         .Replace(RoleDescriptionMarker, roleDescription.Replace("'", "''"));

            DatabaseHelper.ExecuteQuery(script.ToString());
            WebApiTestHelper.ClearHostCache();
            return(GetRoleId(roleName));
        }
Пример #9
0
        public void TryingToRenewUsingAnExpiredRenewalTokenShouldFail()
        {
            var     token1    = GetAuthorizationTokenFor(_hostName, _hostPass);
            var     parts     = token1.AccessToken.Split('.');
            var     decoded   = DecodeBase64(parts[1]);
            dynamic claims    = JsonConvert.DeserializeObject(decoded);
            string  sessionId = claims.sid;
            var     query     = "UPDATE {objectQualifier}JsonWebTokens SET RenewalExpiry=" +
                                $"'{DateTime.UtcNow.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss")}' WHERE TokenId='{sessionId}';";

            DatabaseHelper.ExecuteNonQuery(query);
            WebApiTestHelper.ClearHostCache();

            SetAuthHeaderToken(token1.AccessToken);
            var result = _httpClient.PostAsJsonAsync(ExtendTokenQuery, new { rtoken = token1.RenewalToken }).Result;

            Assert.AreEqual(HttpStatusCode.Unauthorized, result.StatusCode);
        }
Пример #10
0
        public void UsingExpiredRenewalTokenShouldFail()
        {
            var     token1    = this.GetAuthorizationTokenFor(this._hostName, this._hostPass);
            var     parts     = token1.AccessToken.Split('.');
            var     decoded   = DecodeBase64(parts[1]);
            dynamic claims    = JsonConvert.DeserializeObject(decoded);
            string  sessionId = claims.sid;
            var     query     = "UPDATE {objectQualifier}JsonWebTokens SET RenewalExpiry=" +
                                $"'{DateTime.UtcNow.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss")}' WHERE TokenId='{sessionId}';";

            DatabaseHelper.ExecuteNonQuery(query);
            WebApiTestHelper.ClearHostCache();

            this.SetAuthHeaderToken(token1.AccessToken);
            var result  = this._httpClient.GetAsync(TestGetQuery).Result;
            var content = result.Content.ReadAsStringAsync().Result;

            LogText(@"content => " + content);
            Assert.AreEqual(HttpStatusCode.Unauthorized, result.StatusCode);
        }
Пример #11
0
 /// <summary>
 /// Deletes a module from the specified tab and clears host cache.
 /// </summary>
 /// <param name="tabId">tabId on which module is deleted.</param>
 /// <param name="moduleId">moduleId that is deleted.</param>
 /// <param name="softDelete">if True, then softdeleted, otherwise harddeleted.</param>
 public static void DeleteTabModule(int tabId, int moduleId, bool softDelete)
 {
     DatabaseHelper.ExecuteStoredProcedure("DeleteTabModule", tabId, moduleId, softDelete);
     WebApiTestHelper.ClearHostCache();
 }