Example #1
0
        public static int GetLockedUserId(UserManager userMng, UserInfo defaultUser, List <UserInfo> users)
        {
            var currentConnect = PrivateApiConnection.GetConnectionForCurrentTest();
            var prop           = new Dictionary <string, object>()
            {
                ["companyId"]       = defaultUser.Company.Partition,
                ["minLength"]       = MinLength,
                ["checkComplexity"] = "false",
                ["accountLockout"]  = AccountLockout
            };
            var result = userMng.Execute <SettingPasswordResponse>(prop, HttpMethod.Put);

            for (int i = 0; i <= AccountLockout; i++)
            {
                try
                {
                    if (!currentConnect.IsAuthenticated)
                    {
                        currentConnect.Authenticate(users[0].Company.Name, users[0].Login, TestContext.CurrentContext.Random.GetString(MinLength));
                    }
                    else
                    {
                        currentConnect.DeAuthenticate();
                    }
                }
                catch (Exception ex)
                {
                    var mes = ex.Message;
                    continue;
                }
            }
            defaultUser.Dispose();
            return(Int32.Parse(users[0].Metadata["userId"].ToString()));
        }
        public void InvalidSpecialTests(InvalidSpecial condition)
        {
            var userHandler = new UserManager("UnlockUser");
            var propDic     = new Dictionary <string, object>();

            InvalidSpecialMapper[condition](propDic);
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();

            if (condition == InvalidSpecial.ExistedIdWithUserRole)
            {
                Login(connection, NormalUserIds[0].Company.Name, NormalUserIds[0].Login, NormalUserIds[0].Password);
            }
            else if (condition == InvalidSpecial.AlreadyUnlocked)
            {
                userHandler.Execute <UnlockUserResponse>(propDic, System.Net.Http.HttpMethod.Post);
            }
            else if (condition == InvalidSpecial.ErrorConnectDb)
            {
                connection.DeAuthenticate();
            }

            var result = userHandler.Execute <UnlockUserResponse>(propDic, System.Net.Http.HttpMethod.Post);

            PerformTest(result, condition.ToString());
        }
Example #3
0
        public void HappyPathTest(ResourceId resource, FileType fileType)
        {
            var fileInfo     = CommonConstants.Files[fileType];
            var path         = Path.Combine(Util.GetTestDirectory(), fileInfo.Location);
            var base64string = Util.ReadFileAsBase64String(path);
            var recordInfo   = RecordsCreator.Data[resource];
            var handler      = new FileStorageManager();

            var request = GenerateUploadFileRequest(fileName: fileInfo.Location.Split('/').Last(), recordId: recordInfo.Id.ToString(), resourceId: ((int)resource).ToString(), sublist: "1", contentType: fileInfo.MimeType);

            request.Content = base64string;
            var uploadResponse = handler.Upload(request);

            PrAssert.That(uploadResponse, PrIs.SuccessfulResponse());

            //send request as string, not as object, to make sure we receive string as is, without json.NET formatting.
            using (LogHelper.LoggerForCurrentTest.EnterReproStep("Sending request to read file content."))
                using (var readResponse = PrivateApiConnection.GetConnectionForCurrentTest().SendAsync(FileStorageManager.EndPoint, new Dictionary <string, string> {
                    ["id"] = uploadResponse.Result.Id
                }, System.Net.Http.HttpMethod.Get).Result)
                {
                    var receivedContent = readResponse.Content.ReadAsByteArrayAsync().Result;

                    PrAssert.That((int)readResponse.StatusCode, PrIs.LessThan(300));
                    PrAssert.That(receivedContent, PrIs.EqualTo(File.ReadAllBytes(path)));
                }
            var deleteResponse = handler.Delete(uploadResponse.Result.Id);

            PrAssert.That(deleteResponse, PrIs.SuccessfulResponse());
        }
        public void InvalidDeleteGenericRecordTests(ResourceId resource, InvalidDeleteGenericRecord condition)
        {
            var recordHandler = new GenericRecordManager();
            var propDic       = InvalidDeleteGenericRecordRequest(resource, condition);
            var requestData   = new KeyValuePair <string, List <Dictionary <string, object> > >("data", new List <Dictionary <string, object> >()
            {
                propDic
            });

            if (condition == InvalidDeleteGenericRecord.NotLogin)
            {
                PrivateApiConnection.GetConnectionForCurrentTest().DeAuthenticate();
                var result = recordHandler.DeleteRecord <DeleteGenericRecordResponse.Error>(requestData, HttpMethod.Delete);
                PrivateApiConnection.GetConnectionForCurrentTest().Authenticate();
                PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.Unauthorized));
            }
            else if (condition == InvalidDeleteGenericRecord.TransactionError)
            {
                // Currently, we can't test this case so It'll test in the next time
            }
            else
            {
                var result = recordHandler.DeleteRecord <DeleteGenericRecordResponse.Error>(requestData, HttpMethod.Delete);
                PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
            }
        }
Example #5
0
        public void TestValidGetMailsReturnJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var response   = connection.SendAsync(MailGetAndHidden.GetMails, string.Empty, System.Net.Http.HttpMethod.Post).Result;

            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }
        public void ReadInvalidGenericRecordTests(ResourceId resource, InvalidReadGenericRecord condition)
        {
            var recordHandler = new GenericRecordManager();
            var requestDic    = new Dictionary <string, object>()
            {
                ["resource"] = resource.GetHashCode(),
                ["idList"]   = new int[] { Common.ReadRecordsId(resource, FirstSystemRecord) },
                ["fields"]   = string.Format("{0}.P_PhaseDate,{1}.P_Name", resource.ToAlias(), resource.ToAlias())
            };

            if (condition == InvalidReadGenericRecord.NotLogin)
            {
                PrivateApiConnection.GetConnectionForCurrentTest().DeAuthenticate();
                var result = recordHandler.ReadRecord <ReadGenericRecordResponse.Error>(requestDic, HttpMethod.Post);
                PrivateApiConnection.GetConnectionForCurrentTest().Authenticate();
                PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.Unauthorized));
            }
            else if (condition == InvalidReadGenericRecord.TransactionError)
            {
                // This case unable to reproduce at this time.
            }
            else if (condition == InvalidReadGenericRecord.WrongFieldId)
            {
                requestDic["idList"] = WrongId;
                var result = recordHandler.ReadRecord <ReadGenericRecordResponse.Error>(requestDic, HttpMethod.Post);
                PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.InternalServerError));
            }
            else
            {
                requestDic["idList"] = null;
                var result = recordHandler.ReadRecord <ReadGenericRecordResponse.Error>(requestDic, HttpMethod.Post);
                PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
            }
        }
Example #7
0
        public void TestValidGetReturnJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var response   = connection.SendAsync("privateapi/field/field-search", SearchRequest, System.Net.Http.HttpMethod.Get).Result;

            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }
Example #8
0
        public void TestInvalidPostTemplateRequestJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var response   = connection.SendAsync(TemplateEndPoint, JsonConvert.SerializeObject(DefaultCreateRequest), System.Net.Http.HttpMethod.Post, "html/text").Result;

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
Example #9
0
        public void TestValidPostTemplateReturnJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var response   = connection.SendAsync(TemplateEndPoint, JsonConvert.SerializeObject(DefaultCreateRequest), System.Net.Http.HttpMethod.Post).Result;

            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }
 private void PerformTest(PrivateApiResponse <UnlockUserResponse> result, string testcase = null)
 {
     PrAssert.That(result, PrIs.ErrorResponse().With.HttpCode(System.Net.HttpStatusCode.BadRequest));
     if (testcase == InvalidSpecial.ErrorConnectDb.ToString())
     {
         PrivateApiConnection.GetConnectionForCurrentTest().Authenticate(DefaultUser.Company.Name, DefaultUser.Login, DefaultUser.Password);
     }
 }
Example #11
0
        public void TestValidPostReturnJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var request    = TextHelpers.GenerateCreateRequest(ResourceId.Client, Properties.Alias.Min, DefaultProperties);
            var response   = connection.SendAsync(FieldManager.FieldHandlingRelativeUrl, request.ToJson(), System.Net.Http.HttpMethod.Post).Result;

            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }
Example #12
0
        public void TestValidGetTemplatesReturnJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var request    = BuildReadTemplates(TemplateHelpers.Type.Public, EntryPoint.Client, Start.Valid, Count.Valid);
            var response   = connection.SendAsync(TemplateEndPoint, request.ToDictionary(x => x.Key, x => x.Value.ToString()), System.Net.Http.HttpMethod.Get).Result;

            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }
Example #13
0
        public void TestInvalidPutSmtpRequestJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var request    = GenerateCreateOneGlobalRequest();
            var response   = connection.SendAsync(SmtpEndPoint, JsonConvert.SerializeObject(request), System.Net.Http.HttpMethod.Put, "text/html").Result;

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
Example #14
0
        public void ValidReturnJsonContentTypeTest()
        {
            System.Net.Http.HttpResponseMessage response;
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();

            response = connection.SendAsync(EndPoint, string.Empty, HttpMethod.GET.ToNetHttpMethod()).Result;
            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }
Example #15
0
        public void TestValidPostHasDuplicateReturnJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var request    = GenerateDefaultRequest();
            var response   = connection.SendAsync(DuplicateCheckEndpoint, JsonConvert.SerializeObject(request), System.Net.Http.HttpMethod.Post).Result;

            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"), "Media type is wrong");
        }
Example #16
0
        public void TestInvalidPostTemplateReplaceRequestJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var request    = BuildTemplateReplaceRequest(ResourceId.Client, RecordsCreator.Data[$"{ResourceId.Client}0"].Id, Ids.First());
            var response   = connection.SendAsync(TemplateReplaceEndPoint, JsonConvert.SerializeObject(request), System.Net.Http.HttpMethod.Post, "html/text").Result;

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
Example #17
0
        public void UpdateFieldsTest_CheckCachePersistIn3Minutes()
        {
            const string FieldPropertyToModify = "d.label.ja";
            var          resource = ResourceId.Client;
            var          aliases  = new[] { "P_Country", "P_City", "P_Prefecture" };
            var          resetProgrammingCacheField = "P_Memo";
            var          connection   = PrivateApiConnection.GetConnectionForCurrentTest();
            var          fieldHandler = new FieldManager();

            //1. Update fields in DB1
            fieldHandler.UpdateField(resetProgrammingCacheField, ResourceId.Client, new Dictionary <string, object> {
                ["d.label.ja"] = "MEMO"
            });

            var originalValues = aliases.ToDictionary(x => x, x => fieldHandler.GetFieldDetails($"{resource}.{x}").Result.Values.Single().Value);

            foreach (var alias in aliases)
            {
                fieldHandler.UpdateField(alias, ResourceId.Client, new Dictionary <string, object> {
                    [FieldPropertyToModify] = $"UPDATE_{alias.ToUpper()}_1"
                });
            }
            //2. Logout
            connection.DeAuthenticate();
            connection.DeleteAllCookies();
            //3. Wait for 3 minutes.
            //MANUAL PART: withing this time, update companies table, restart memcache
            System.Threading.Thread.Sleep(new TimeSpan(0, 3, 0));
            //4. Make sure that data is still in cache by reading the updated fields
            connection.Authenticate();
            fieldHandler.UpdateField(resetProgrammingCacheField, ResourceId.Client, new Dictionary <string, object> {
                ["d.label.ja"] = "MEMO"
            });
            var updatedValues = aliases.ToDictionary(x => x, x => fieldHandler.GetFieldDetails($"{resource}.{x}").Result.Values.Single().Value);

            foreach (var alias in aliases)
            {
                PrAssert.That(originalValues[alias].Properties[FieldPropertyToModify], PrIs.Not.EqualTo(updatedValues[alias].Properties[FieldPropertyToModify]));
            }
            connection.DeAuthenticate();
            connection.DeleteAllCookies();
            //5. Wait for a bit more that 5 minutes for cache to expire
            //MANUAL PART: restart memcache
            System.Threading.Thread.Sleep(new TimeSpan(0, 5, 5));
            //6. Read updated fields, make sure they contain default value
            connection.Authenticate();

            fieldHandler.UpdateField(resetProgrammingCacheField, ResourceId.Client, new Dictionary <string, object> {
                ["d.label.ja"] = "MEMO"
            });

            updatedValues = aliases.ToDictionary(x => x, x => fieldHandler.GetFieldDetails($"{resource}.{x}").Result.Values.Single().Value);

            foreach (var alias in aliases)
            {
                PrAssert.That(originalValues[alias].Properties[FieldPropertyToModify], PrIs.EqualTo(updatedValues[alias].Properties[FieldPropertyToModify]));
            }
        }
Example #18
0
 public void DeAuthenticatedAccessTest()
 {
     using (LogHelper.LoggerForCurrentTest.EnterReproStep("Test If we can access the feature while being DeAuthenticated"))
     {
         PrivateApiConnection.GetConnectionForCurrentTest().DeAuthenticate();
         PerformDateTimeConvertTest(DefaultFromValue, DefaultToValue, DefaultDateTimes, (response) =>
                                    CheckResponseIsSuccessAndAllAreEqualTo(response, TestTimes));
     }
 }
        public void ValidPostReturnJsonContentTypeTest()
        {
            System.Net.Http.HttpResponseMessage response;
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var request    = GetDataToCreateRequest(null, ResourceType.Client, ReportHelper.Constraint.Empty, "P_Id", Graph.Line, Function.None, Function.None);

            response = connection.SendAsync(EndPoint, request, HttpMethod.POST.ToNetHttpMethod()).Result;
            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }
Example #20
0
        public void TestValidPostFieldLayoutReturnJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var fieldUuid  = FieldsCreator.Data[$"{ResourceId.Client}-{FieldType.SingleLineText.ToString()}-0"].Guid;
            var request    = GenerateFieldLayoutRequest(ResourceId.Client, fieldUuid, Title.MinJa, Row.Min, Column.Min, CellContent.Field);
            var response   = connection.SendAsync(FieldManager.FieldLayoutApiRelativeUrl, JsonConvert.SerializeObject(request), System.Net.Http.HttpMethod.Post).Result;

            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }
Example #21
0
        public void TestInvalidPutSortTemplatesRequestJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var request    = BuildSortRequest(1, new List <int> {
                Ids.First()
            });
            var response = connection.SendAsync(TemplatesEndPoint, JsonConvert.SerializeObject(request), System.Net.Http.HttpMethod.Put, "html/text").Result;

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
Example #22
0
        public void ArbitraryStringTest()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();

            using (LogHelper.LoggerForCurrentTest.EnterReproStep("Sending arbitrary string to date time convert API"))
                using (var response = connection.SendAsync("privateapi/noauth/datetime/convert", "ARBITRARY_STRING", System.Net.Http.HttpMethod.Post).Result)
                {
                    PrAssert.That(!response.IsSuccessStatusCode);
                }
        }
Example #23
0
        public void WrongJsonInReqeustTest(Func <SearchRequest, string> jsonTransformation, string testCaseName)
        {
            var requestString = jsonTransformation(DefaultSearchReqeust);
            var connection    = PrivateApiConnection.GetConnectionForCurrentTest();

            using (var response = connection.SendAsync(SearchManager.EndPoint, requestString, System.Net.Http.HttpMethod.Post).Result)
            {
                PrAssert.That(!response.IsSuccessStatusCode, "A request with wrong HTTP method was successful, while expected fail");
            }
        }
Example #24
0
        public void AccessFeatureWithContentTypeTest(string contentType)
        {
            var requestString = Newtonsoft.Json.JsonConvert.SerializeObject(DefaultSearchReqeust);
            var connection    = PrivateApiConnection.GetConnectionForCurrentTest();

            using (var response = connection.SendAsync(SearchManager.EndPoint, requestString, System.Net.Http.HttpMethod.Post, contentType).Result)
            {
                PrAssert.That(!response.IsSuccessStatusCode, "A request with wrong HTTP method was successful, while expected fail");
            }
        }
Example #25
0
        private void ExecuteTest(Dictionary <string, string> request)
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();

            connection.SuppressAuthentication = true;
            var defaultManager = new DefaultManager(connection);
            var result         = defaultManager.Send <object>(PartitionTestCases.EndpointMapper[HttpMethod.POST], JsonConvert.SerializeObject(request), HttpMethod.POST);

            PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest), $"Still create partition with invalid value.");
        }
Example #26
0
        public void TestValidGetNewMailsReturnJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var request    = new Dictionary <string, object>();

            GetAndHiddenTestData.ValidGetMailsMapperValue[GetAndHiddenTestData.Valid.One](request, GetAndHiddenTestData.ListView, new List <int>());
            var response = connection.SendAsync(MailGetAndHidden.GetNewMails, request.ToJson(), System.Net.Http.HttpMethod.Post).Result;

            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }
Example #27
0
        public void TestValidGetReturnJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var request    = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>(Selects.IdParam, FieldsCreator.Data[$"{ResourceId.Client}-{FieldType.Mail.ToString()}-0"].Guid.ToString())
            };
            var response = connection.SendAsync(FieldManager.FieldHandlingRelativeUrl, request, System.Net.Http.HttpMethod.Get).Result;

            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }
Example #28
0
        public void TestValidGetFieldLayoutReturnJsonContentType()
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var request    = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>(IdParam, ReadFieldLayoutId.ToString())
            };
            var response = connection.SendAsync(FieldManager.FieldLayoutApiRelativeUrl, request, System.Net.Http.HttpMethod.Get).Result;

            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }
Example #29
0
        public void AuthenticationStatusAccessTest(bool doDeauth)
        {
            if (doDeauth)
            {
                PrivateApiConnection.GetConnectionForCurrentTest().DeAuthenticate();
            }
            var handler  = new DefaultManager();
            var response = handler.Send(DefaultSearchReqeust);

            PrAssert.That(response, PrIs.ErrorResponse().And.ErrorCode(5).And.HttpCode(401));
        }
Example #30
0
        public void TestValidGetOthersSmtpReturnJsonContentType(OtherParameters param)
        {
            var connection = PrivateApiConnection.GetConnectionForCurrentTest();
            var request    = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>(param.GetEnumStringValue(), "0")
            };
            var response = connection.SendAsync(param == OtherParameters.AllowUserSpecific ? SmtpSpecificEndPoint : SmtpDefaultEndPoint, request, System.Net.Http.HttpMethod.Get).Result;

            PrAssert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }