Ejemplo n.º 1
0
        public async Task GetPageOrder_NoCustomConfigurationLayoutSet_PageOrderIsRetrievedFromAppBaseAndReturned()
        {
            string        org      = "ttd";
            string        app      = "frontend-test";
            List <string> expected = new List <string> {
                "formLayout", "summary"
            };

            // Using default app here to not reference App.cs in the app repo.
            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);
            string     token  = PrincipalUtil.GetToken(1337);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpRequestMessage httpRequestMessage =
                new HttpRequestMessage(HttpMethod.Post, $"/{org}/{app}/instances/1001/26133fb5-a9f2-45d4-90b1-f6d93ad40713/pages/order?layoutSetId=changename&dataTypeId=message");

            httpRequestMessage.Content = new StringContent("{\"skjemanummer\": \"1337\"}", Encoding.UTF8, "application/json");

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            List <string> actual = JsonConvert.DeserializeObject <List <string> >(responseContent);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 2
0
        public async Task Instance_Post_WithQueryParamInvalidCsrf_AuthCookie()
        {
            string token = PrincipalUtil.GetToken(1);

            HttpClient         client = SetupUtil.GetTestClient(_factory, "tdd", "endring-av-navn");
            HttpRequestMessage httpRequestMessageHome = new HttpRequestMessage(HttpMethod.Get, "/tdd/endring-av-navn/")
            {
            };

            SetupUtil.AddAuthCookie(httpRequestMessageHome, token);

            HttpResponseMessage responseHome = await client.SendAsync(httpRequestMessageHome);

            string             xsrfToken          = SetupUtil.GetXsrfCookieValue(responseHome);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/tdd/endring-av-navn/instances?instanceOwnerPartyId=1000")
            {
            };

            xsrfToken = xsrfToken + "THIS_MAKE_THE_TOKEN_INVALID";
            SetupUtil.AddAuthCookie(httpRequestMessage, token, xsrfToken);

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
Ejemplo n.º 3
0
        public async Task Proceess_Put_Next_OK()
        {
            TestDataUtil.DeleteInstanceAndData("tdd", "endring-av-navn", 1337, new System.Guid("26233fb5-a9f2-45d4-90b1-f6d93ad40713"));
            TestDataUtil.PrepareInstance("tdd", "endring-av-navn", 1337, new System.Guid("26233fb5-a9f2-45d4-90b1-f6d93ad40713"));
            string token = PrincipalUtil.GetToken(1337);

            string instancePath = "/tdd/endring-av-navn/instances/1337/26233fb5-a9f2-45d4-90b1-f6d93ad40713";

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "endring-av-navn");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, $"{instancePath}/process/start");

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, $"{instancePath}/process/next");

            response = await client.SendAsync(httpRequestMessage);

            responseContent = await response.Content.ReadAsStringAsync();

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            TestDataUtil.DeleteInstanceAndData("tdd", "endring-av-navn", 1337, new System.Guid("26233fb5-a9f2-45d4-90b1-f6d93ad40713"));
        }
Ejemplo n.º 4
0
        public async Task Data_Post_ValidComplexFileName_Ok()
        {
            string app  = "contributer-restriction";
            Guid   guid = new Guid("0fc98a23-fe31-4ef5-8fb9-dd3f479354cd");

            TestDataUtil.DeleteInstance("tdd", app, 1337, guid);
            TestDataUtil.PrepareInstance("tdd", app, 1337, guid);
            string token = PrincipalUtil.GetOrgToken("nav", "160694123");

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", app);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string      url     = $"/tdd/{app}/instances/1337/{guid}/data?dataType=specificFileType";
            HttpContent content = new StringContent(string.Empty);

            content.Headers.ContentType        = MediaTypeHeaderValue.Parse("application/json");
            content.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("attachment; filename=appsettings.development.json");

            HttpResponseMessage response = await client.PostAsync(url, content);

            string message = await response.Content.ReadAsStringAsync();

            TestDataUtil.DeleteInstanceAndData("tdd", app, 1337, guid);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
Ejemplo n.º 5
0
        public async Task Instance_Post_WithInstantiationValidationFail()
        {
            string token = PrincipalUtil.GetToken(1337);

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "custom-validation");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/tdd/custom-validation/instances?instanceOwnerPartyId=1337")
            {
            };

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            InstantiationValidationResult validationResult = JsonConvert.DeserializeObject <InstantiationValidationResult>(responseContent);

            if (DateTime.Now.Hour < 15)
            {
                Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
                Assert.False(validationResult.Valid);
                Assert.Equal("ERROR: Instantiation not possible before 3PM.", validationResult.Message);
            }
            else
            {
                Assert.Equal(HttpStatusCode.Created, response.StatusCode);
                Instance createdInstance = JsonConvert.DeserializeObject <Instance>(await response.Content.ReadAsStringAsync());

                Assert.NotNull(createdInstance);
                Assert.Single(createdInstance.Data);
                Assert.Equal("default", createdInstance.Data[0].DataType);

                TestDataUtil.DeleteInstanceAndData("tdd", "custom-validering", 1337, new Guid(createdInstance.Id.Split('/')[1]));
            }
        }
Ejemplo n.º 6
0
        public async Task StatelessData_Post_ObjectSucessfullyPrefilledAndCalculated()
        {
            // Arrange
            string org = "ttd";
            string app = "presentationfields-app";
            string expectedPrefillValue    = "Sophie Salt";
            string expectedCalculatedValue = "calculatedValue";
            string token = PrincipalUtil.GetToken(1337);

            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string requestUri = $"/{org}/{app}/v1/data?dataType=default";

            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri);

            // Act
            HttpResponseMessage res = await client.SendAsync(httpRequestMessage);

            string responseContent = await res.Content.ReadAsStringAsync();

            Mocks.Apps.Ttd.PresentationTextsApp.Skjema dataObject = JsonConvert.DeserializeObject <Mocks.Apps.Ttd.PresentationTextsApp.Skjema>(responseContent);
            string actualPrefillValue    = dataObject?.OpplysningerOmArbeidstakerengrp8819?.Arbeidsforholdgrp8856?.AnsattSammenhengendeAnsattAnsettelsedatadef33267?.value;
            string actualCalculatedValue = dataObject?.OpplysningerOmArbeidstakerengrp8819?.Skjemainstansgrp8854?.IdentifikasjonsnummerKravdatadef33317?.value;

            // Assert
            Assert.Equal(HttpStatusCode.OK, res.StatusCode);
            Assert.NotNull(actualPrefillValue);
            Assert.NotNull(actualCalculatedValue);
            Assert.Equal(expectedPrefillValue, actualPrefillValue);
            Assert.Equal(expectedCalculatedValue, actualCalculatedValue);
        }
Ejemplo n.º 7
0
        public async Task Data_Post_WithContributerOrgRestriction_Ok()
        {
            string app  = "contributer-restriction";
            Guid   guid = new Guid("0fc98a23-fe31-4ef5-8fb9-dd3f479354cd");

            TestDataUtil.DeleteInstance("tdd", app, 1337, guid);
            TestDataUtil.PrepareInstance("tdd", app, 1337, guid);
            string token = PrincipalUtil.GetOrgToken("tdd");

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", app);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string      url     = $"/tdd/{app}/instances/1337/{guid}/data?dataType=customElement";
            HttpContent content = new StringContent(string.Empty);

            content.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("attachment; filename=test.pdf");

            HttpResponseMessage response = await client.PostAsync(url, content);

            await response.Content.ReadAsStringAsync();

            TestDataUtil.DeleteInstanceAndData("tdd", app, 1337, guid);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
        public async Task GetCurrentPartyWithPartyCookieForOther_ReturnSelfParty_OK()
        {
            // Arrange
            string     token  = PrincipalUtil.GetToken(1);
            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "endring-av-navn");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "/tdd/endring-av-navn/api/authorization/parties/current?returnPartyObject=true");

            AddPartyCookie(httpRequestMessage, 500003);

            // Act
            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            // Assert
            string responseContent = await response.Content.ReadAsStringAsync();

            IEnumerable <string> cookieHeaders = response.Headers.GetValues("Set-Cookie");
            bool cookieIsSet = false;

            foreach (string cookie in cookieHeaders)
            {
                if (cookie.Contains("AltinnPartyId=1000"))
                {
                    cookieIsSet = true;
                }
            }

            Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
            Party party = JsonConvert.DeserializeObject <Party>(responseContent);

            Assert.Equal(1000, party.PartyId);
            Assert.True(cookieIsSet);
        }
Ejemplo n.º 9
0
        public async void AddCompleteConfirmation_PostAsValidAppOwner_RespondsWithUpdatedInstance()
        {
            // Arrange
            string org = "tdd";
            string app = "endring-av-navn";
            int    instanceOwnerPartyId = 1337;
            string instanceGuid         = "66233fb5-a9f2-45d4-90b1-f6d93ad40713";

            TestDataUtil.DeleteInstanceAndData(org, app, instanceOwnerPartyId, new Guid(instanceGuid));
            TestDataUtil.PrepareInstance(org, app, instanceOwnerPartyId, new Guid(instanceGuid));

            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);

            string token = PrincipalUtil.GetOrgToken(org);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string requestUri = $"/{org}/{app}/instances/{instanceOwnerPartyId}/{instanceGuid}/complete";

            // Act
            HttpResponseMessage response = await client.PostAsync(requestUri, new StringContent(string.Empty));

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            string json = await response.Content.ReadAsStringAsync();

            Instance updatedInstance = JsonConvert.DeserializeObject <Instance>(json);

            // Don't compare original and updated instance in asserts. The two instances are identical.
            Assert.NotNull(updatedInstance);
            Assert.Equal(org, updatedInstance.CompleteConfirmations[0].StakeholderId);
            Assert.Equal($"{instanceOwnerPartyId}/{instanceGuid}", updatedInstance.Id);
        }
Ejemplo n.º 10
0
        public async Task ValidateForm_CustomValidation_InvalidData()
        {
            TestDataUtil.DeleteInstance("tdd", "custom-validation", 1337, new System.Guid("0fc98a23-fe31-4ef5-8fb9-dd3f479354cd"));
            TestDataUtil.PrepareInstance("tdd", "custom-validation", 1337, new System.Guid("0fc98a23-fe31-4ef5-8fb9-dd3f479354cd"));
            string token = PrincipalUtil.GetToken(1337);

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "custom-validation");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "/tdd/custom-validation/instances/1337/0fc98a23-fe31-4ef5-8fb9-dd3f479354cd/validate");

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            TestDataUtil.DeleteInstance("tdd", "custom-validation", 1337, new System.Guid("0fc98a23-fe31-4ef5-8fb9-dd3f479354cd"));
            System.Console.WriteLine("**** RESPONSE CONTENT: " + responseContent);
            System.Console.WriteLine("**** RESPONSE STATUD CODE: " + response.StatusCode);
            List <ValidationIssue> messages = (List <ValidationIssue>)JsonConvert.DeserializeObject(responseContent, typeof(List <ValidationIssue>));

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Single(messages);
            Assert.Equal(ValidationIssueSeverity.Error, messages[0].Severity);
            Assert.Equal("Value cannot be 1234", messages[0].Code);
        }
Ejemplo n.º 11
0
        public async Task ValidateForm_ModelValidation_InvalidData()
        {
            TestDataUtil.DeleteInstance("tdd", "custom-validation", 1337, new System.Guid("46133fb5-a9f2-45d4-90b1-f6d93ad40713"));
            TestDataUtil.PrepareInstance("tdd", "custom-validation", 1337, new System.Guid("46133fb5-a9f2-45d4-90b1-f6d93ad40713"));

            string token = PrincipalUtil.GetToken(1337);

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "custom-validation");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "/tdd/custom-validation/instances/1337/46133fb5-a9f2-45d4-90b1-f6d93ad40713/validate");

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            TestDataUtil.DeleteInstance("tdd", "custom-validation", 1337, new System.Guid("46133fb5-a9f2-45d4-90b1-f6d93ad40713"));

            List <ValidationIssue> messages = (List <ValidationIssue>)JsonConvert.DeserializeObject(responseContent, typeof(List <ValidationIssue>));

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Single(messages);
            Assert.Equal(ValidationIssueSeverity.Error, messages[0].Severity);
            Assert.Equal("ERROR: Max length is 11", messages[0].Code);
        }
Ejemplo n.º 12
0
        public async Task ValidateTask_InvalidTime()
        {
            // Arrange
            TestDataUtil.DeleteInstanceAndData("tdd", "task-validation", 1337, new System.Guid("16314483-65f3-495a-aaec-79445b4edb0b"));
            TestDataUtil.PrepareInstance("tdd", "task-validation", 1337, new System.Guid("16314483-65f3-495a-aaec-79445b4edb0b"));
            string token       = PrincipalUtil.GetToken(1337);
            string expectedMsg = "Task 1 should have been completed within 48 hours. Send in is no longer available.";

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "task-validation");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            string url = "/tdd/task-validation/instances/1337/16314483-65f3-495a-aaec-79445b4edb0b/validate";

            // Act
            HttpResponseMessage response = await client.GetAsync(url);

            string responseContent = await response.Content.ReadAsStringAsync();

            TestDataUtil.DeleteInstanceAndData("tdd", "task-validation", 1337, new System.Guid("16314483-65f3-495a-aaec-79445b4edb0b"));

            List <ValidationIssue> messages = (List <ValidationIssue>)JsonConvert.DeserializeObject(responseContent, typeof(List <ValidationIssue>));

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Single(messages);
            Assert.Equal(ValidationIssueSeverity.Error, messages[0].Severity);
            Assert.Equal(expectedMsg, messages[0].Code);
        }
        public async Task Instance_Put_FailsOK()
        {
            string token = PrincipalUtil.GetToken(1);

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "platform-fails");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            Instance instance = new Instance
            {
                Id            = $"1000/26133fb5-a9f2-45d4-90b1-f6d93ad40713",
                Org           = "tdd",
                AppId         = "tdd/platform-fails",
                InstanceOwner = new InstanceOwner
                {
                    PartyId = "1000",
                },
            };

            StringContent httpContent = new StringContent(instance.ToString(), Encoding.UTF8, "application/json");

            HttpResponseMessage response = await client.PutAsync("/tdd/platform-fails/instances/1000/26133fb5-a9f2-45d4-90b1-f6d93ad40713",
                                                                 httpContent);

            Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
        }
Ejemplo n.º 14
0
        public async Task GetPageOrder_NoCustomConfiguration_PageOrderIsRetrievedFromAppBaseAndReturned()
        {
            string        org      = "ttd";
            string        app      = "events";
            List <string> expected = new List <string> {
                "FormLayout", "Side2"
            };

            // Using default app here to not reference App.cs in the app repo.
            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);
            string     token  = PrincipalUtil.GetToken(1337);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpRequestMessage httpRequestMessage =
                new HttpRequestMessage(HttpMethod.Get, $"/{org}/{app}/instances/1001/26133fb5-a9f2-45d4-90b1-f6d93ad40713/pages/order");

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            List <string> actual = JsonConvert.DeserializeObject <List <string> >(responseContent);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 15
0
        public async Task Profile_GetBySSN_OK()
        {
            // Arrange
            string        token       = PrincipalUtil.GetToken(12345);
            StringContent requestBody = new StringContent(JsonConvert.SerializeObject("01017512345"), Encoding.UTF8, "application/json");

            HttpClient client = SetupUtil.GetTestClient(_factory);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            int expectedUserId = 12345;

            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/profile/api/v1/users/")
            {
                Content = requestBody
            };

            httpRequestMessage.Headers.Add("PlatformAccessToken", PrincipalUtil.GetAccessToken("ttd", "unittest"));

            // Act
            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            UserProfile actual = JsonConvert.DeserializeObject <UserProfile>(await response.Content.ReadAsStringAsync());

            // Assert
            Assert.Equal(expectedUserId, actual.UserId);
        }
Ejemplo n.º 16
0
        public async void AddCompleteConfirmation_AttemptToCompleteInstanceAsUser_ReturnsForbidden()
        {
            // Arrange
            string org = "tdd";
            string app = "endring-av-navn";
            int    instanceOwnerPartyId = 1337;
            string instanceGuid         = "66233fb5-a9f2-45d4-90b1-f6d93ad40713";

            TestDataUtil.DeleteInstanceAndData(org, app, instanceOwnerPartyId, new Guid(instanceGuid));
            TestDataUtil.PrepareInstance(org, app, instanceOwnerPartyId, new Guid(instanceGuid));

            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);

            string token = PrincipalUtil.GetToken(21023); // 21023 is connected to party with id 1337

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string requestUri = $"/{org}/{app}/instances/{instanceOwnerPartyId}/{instanceGuid}/complete";

            // Act
            HttpResponseMessage response = await client.PostAsync(requestUri, new StringContent(string.Empty));

            // Assert
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
        }
Ejemplo n.º 17
0
        public async Task StatelessData_Put_InvalidDataType()
        {
            // Arrange
            string org = "ttd";
            string app = "model-validation";

            string token = PrincipalUtil.GetToken(1337);

            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string requestUri = $"/{org}/{app}/v1/data?dataType=tix";

            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, requestUri)
            {
                Content = new StringContent("{}", Encoding.UTF8, "application/json")
            };

            // Act
            HttpResponseMessage res = await client.SendAsync(httpRequestMessage);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, res.StatusCode);
        }
Ejemplo n.º 18
0
        public async void UpdateSubstatus_MissingLabel_ReturnsBadRequest()
        {
            // Arrange
            string org = "tdd";
            string app = "endring-av-navn";
            int    instanceOwnerPartyId = 1337;
            string instanceGuid         = "66233fb5-a9f2-45d4-90b1-f6d93ad40713";

            Substatus substatus = new Substatus {
                Description = "Substatus.Approved.Description"
            };
            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);

            string token = PrincipalUtil.GetOrgToken(org);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string             requestUri         = $"/{org}/{app}/instances/{instanceOwnerPartyId}/{instanceGuid}/substatus";
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, requestUri);

            httpRequestMessage.Content = new StringContent(JsonConvert.SerializeObject(substatus), Encoding.UTF8, "application/json");

            // Act
            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
Ejemplo n.º 19
0
        public async Task StatelessData_Put_CalculationsRunAndDataReturned()
        {
            // Arrange
            string  org      = "ttd";
            string  app      = "model-validation";
            decimal expected = 1001;

            string token = PrincipalUtil.GetToken(1337);

            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string requestUri  = $"/{org}/{app}/v1/data?dataType=default";
            string requestBody = "{\"skjemanummer\":\"1472\",\"spesifikasjonsnummer\":\"9812\",\"blankettnummer\":\"AFP-01\",\"tittel\":\"ArbeidsgiverskjemaAFP\",\"gruppeid\":\"8818\",\"OpplysningerOmArbeidstakerengrp8819\":{\"Arbeidsforholdgrp8856\":{\"AnsattSammenhengendeAnsattAnsettelsedatadef33267\":{\"value\":\"SophieSalt\",\"orid\":\"33267\"},},\"Skjemainstansgrp8854\":{\"Journalnummerdatadef33316\":{\"value\":\"1000\"}}}}";

            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, requestUri)
            {
                Content = new StringContent(requestBody, Encoding.UTF8, "application/json")
            };

            // Act
            HttpResponseMessage res = await client.SendAsync(httpRequestMessage);

            string responseContent = await res.Content.ReadAsStringAsync();

            Mocks.Apps.ttd.model_validation.Skjema dataObject = JsonConvert.DeserializeObject <Mocks.Apps.ttd.model_validation.Skjema>(responseContent);
            decimal?actual = dataObject?.OpplysningerOmArbeidstakerengrp8819?.Skjemainstansgrp8854?.Journalnummerdatadef33316?.value;

            // Assert
            Assert.Equal(HttpStatusCode.OK, res.StatusCode);
            Assert.NotNull(actual);
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 20
0
        public async void UpdateSubstatus_EndUserTriestoSetSubstatus_ReturnsForbidden()
        {
            // Arrange
            string org = "tdd";
            string app = "endring-av-navn";
            int    instanceOwnerPartyId = 1337;
            string instanceGuid         = "66233fb5-a9f2-45d4-90b1-f6d93ad40713";

            TestDataUtil.PrepareInstance(org, app, instanceOwnerPartyId, new Guid(instanceGuid));

            Substatus substatus = new Substatus {
                Label = "Substatus.Approved.Label", Description = "Substatus.Approved.Description"
            };
            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);

            string token = PrincipalUtil.GetToken(21023); // 21023 is connected to party with id 1337

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string             requestUri         = $"/{org}/{app}/instances/{instanceOwnerPartyId}/{instanceGuid}/substatus";
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, requestUri);

            httpRequestMessage.Content = new StringContent(JsonConvert.SerializeObject(substatus), Encoding.UTF8, "application/json");

            // Act
            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            TestDataUtil.DeleteInstance(org, app, instanceOwnerPartyId, new Guid(instanceGuid));

            // Assert
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
        }
Ejemplo n.º 21
0
        public async Task Data_Post_MissingContentDispHeader_BadRequest()
        {
            string app  = "contributer-restriction";
            Guid   guid = new Guid("0fc98a23-fe31-4ef5-8fb9-dd3f479354cd");

            TestDataUtil.DeleteInstance("tdd", app, 1337, guid);
            TestDataUtil.PrepareInstance("tdd", app, 1337, guid);
            string token       = PrincipalUtil.GetOrgToken("nav", "160694123");
            string expectedMsg = "Invalid data provided. Error: Conent-Disposition header containing 'filename' must be included in request.";

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", app);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string      url     = $"/tdd/{app}/instances/1337/{guid}/data?dataType=specificFileType";
            HttpContent content = new StringContent(string.Empty);

            HttpResponseMessage response = await client.PostAsync(url, content);

            string message = await response.Content.ReadAsStringAsync();

            TestDataUtil.DeleteInstanceAndData("tdd", app, 1337, guid);

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.Equal(expectedMsg, message);
        }
Ejemplo n.º 22
0
        public async void DeleteInstance_UnauthorizedUserAttemptsToDelete_ReturnsForbidden()
        {
            string org = "tdd";
            string app = "endring-av-navn";
            int    instanceOwnerPartyId = 1337;
            string instanceGuid         = "66233fb5-a9f2-45d4-90b1-f6d93ad40713";

            TestDataUtil.DeleteInstanceAndData(org, app, instanceOwnerPartyId, new Guid(instanceGuid));
            TestDataUtil.PrepareInstance(org, app, instanceOwnerPartyId, new Guid(instanceGuid));

            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);
            string     token  = PrincipalUtil.GetToken(21023); // 21023 is connected to party with id 1337

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string             requestUri         = $"/{org}/{app}/instances/{instanceOwnerPartyId}/{instanceGuid}";
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Delete, requestUri);

            // Act
            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            TestDataUtil.DeleteInstanceAndData(org, app, instanceOwnerPartyId, new Guid(instanceGuid));

            // Assert
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
        }
Ejemplo n.º 23
0
        public async Task Data_Post_MisMatchContentTypeFileType_BadRequest()
        {
            string app  = "contributer-restriction";
            Guid   guid = new Guid("0fc98a23-fe31-4ef5-8fb9-dd3f479354cd");

            TestDataUtil.DeleteInstance("tdd", app, 1337, guid);
            TestDataUtil.PrepareInstance("tdd", app, 1337, guid);
            string token       = PrincipalUtil.GetOrgToken("nav", "160694123");
            string expectedMsg = "Invalid data provided. Error: Content type header text/xml does not match mime type application/pdf for uploaded file. Please fix header or upload another file.";

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", app);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string      url     = $"/tdd/{app}/instances/1337/{guid}/data?dataType=specificFileType";
            HttpContent content = new StringContent(string.Empty);

            content.Headers.ContentType        = MediaTypeHeaderValue.Parse("text/xml");
            content.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("attachment; filename=testfile.pdf");

            HttpResponseMessage response = await client.PostAsync(url, content);

            string message = await response.Content.ReadAsStringAsync();

            TestDataUtil.DeleteInstanceAndData("tdd", app, 1337, guid);

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.Equal(expectedMsg, message);
        }
Ejemplo n.º 24
0
        public async void DeleteInstance_AppOwnerSoftDletesInstance_DeleteSetOnInstance()
        {
            string org = "tdd";
            string app = "endring-av-navn";
            int    instanceOwnerPartyId = 1337;
            string instanceGuid         = "66233fb5-a9f2-45d4-90b1-f6d93ad40713";

            TestDataUtil.DeleteInstanceAndData(org, app, instanceOwnerPartyId, new Guid(instanceGuid));
            TestDataUtil.PrepareInstance(org, app, instanceOwnerPartyId, new Guid(instanceGuid));

            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);
            string     token  = PrincipalUtil.GetOrgToken("tdd");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string             requestUri         = $"/{org}/{app}/instances/{instanceOwnerPartyId}/{instanceGuid}";
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Delete, requestUri);

            // Act
            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            TestDataUtil.DeleteInstanceAndData(org, app, instanceOwnerPartyId, new Guid(instanceGuid));

            string json = await response.Content.ReadAsStringAsync();

            Instance deletedInstance = JsonConvert.DeserializeObject <Instance>(json);

            // Assert
            Assert.Null(deletedInstance.Status.HardDeleted);
            Assert.NotNull(deletedInstance.Status.SoftDeleted);
        }
Ejemplo n.º 25
0
        public async Task Instance_Post_WithQueryParamOk_AuthCookie()
        {
            string token = PrincipalUtil.GetToken(1337);

            HttpClient         client = SetupUtil.GetTestClient(_factory, "tdd", "endring-av-navn");
            HttpRequestMessage httpRequestMessageHome = new HttpRequestMessage(HttpMethod.Get, "/tdd/endring-av-navn/")
            {
            };

            SetupUtil.AddAuthCookie(httpRequestMessageHome, token);

            HttpResponseMessage responseHome = await client.SendAsync(httpRequestMessageHome);

            string             xsrfToken          = SetupUtil.GetXsrfCookieValue(responseHome);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/tdd/endring-av-navn/instances?instanceOwnerPartyId=1337")
            {
            };

            SetupUtil.AddAuthCookie(httpRequestMessage, token, xsrfToken);

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            Instance instance = JsonConvert.DeserializeObject <Instance>(responseContent);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.NotNull(instance);
            Assert.Equal("1337", instance.InstanceOwner.PartyId);

            TestDataUtil.DeleteInstanceAndData("tdd", "endring-av-navn", 1337, new Guid(instance.Id.Split('/')[1]));
        }
Ejemplo n.º 26
0
        public async Task Profile_Get_OK()
        {
            string token = PrincipalUtil.GetToken(1337);

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "endring-av-navn");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "/tdd/endring-av-navn/api/v1/profile/user/")
            {
            };

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            string profileData = await response.Content.ReadAsStringAsync();

            UserProfile profile = JsonConvert.DeserializeObject <UserProfile>(profileData);

            Assert.Equal(1337, profile.UserId);
            Assert.Equal("SophieDDG", profile.UserName);
            Assert.Equal("Sophie Salt", profile.Party.Name);
            Assert.Equal("90001337", profile.PhoneNumber);
            Assert.Equal(1337, profile.PartyId);
            Assert.Equal("01039012345", profile.Party.SSN);
            Assert.Equal("*****@*****.**", profile.Email);
            Assert.Equal("Sophie", profile.Party.Person.FirstName);
            Assert.Equal("Salt", profile.Party.Person.LastName);
            Assert.Equal("0151", profile.Party.Person.AddressPostalCode);
            Assert.Equal("Oslo", profile.Party.Person.AddressCity);
            Assert.Equal("Grev Wedels Plass", profile.Party.Person.AddressStreetName);
            Assert.Equal("9", profile.Party.Person.AddressHouseNumber);
        }
Ejemplo n.º 27
0
        public async Task Instance_Post_WithLowAuthLevel_FailOk()
        {
            string token = PrincipalUtil.GetToken(1337, 1);

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "endring-av-navn");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/tdd/endring-av-navn/instances?instanceOwnerPartyId=1337")
            {
            };

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            Dictionary <string, string> failedObligations = JsonConvert.DeserializeObject <Dictionary <string, string> >(responseContent);

            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
            Assert.NotNull(failedObligations);

            Dictionary <string, string> expectedFailedObligations = new Dictionary <string, string>()
            {
                { "RequiredAuthenticationLevel", "2" }
            };

            Assert.Equal(expectedFailedObligations, failedObligations);
        }
Ejemplo n.º 28
0
        public async Task Profile_GetBySSN_NotFound()
        {
            // Arrange
            string        token       = PrincipalUtil.GetToken(12345);
            StringContent requestBody = new StringContent(JsonConvert.SerializeObject("123456789"), Encoding.UTF8, "application/json");

            HttpClient client = SetupUtil.GetTestClient(_factory);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            HttpStatusCode expected = HttpStatusCode.NotFound;

            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/profile/api/v1/users/")
            {
                Content = requestBody
            };

            httpRequestMessage.Headers.Add("PlatformAccessToken", PrincipalUtil.GetAccessToken("ttd", "unittest"));

            // Act
            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            HttpStatusCode actual = response.StatusCode;

            // Assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 29
0
        public async Task Next_RegistrationOfEventsTurnedOn_ControllerCallsEventWithCorrectType()
        {
            string org          = "ttd";
            string app          = "events";
            int    partyId      = 1337;
            string instanceGuid = "bffd2c17-9d93-49f4-b504-3d0ece2402c6";

            TestDataUtil.DeleteInstanceAndData(org, app, partyId, new Guid(instanceGuid));
            TestDataUtil.PrepareInstance(org, app, partyId, new Guid(instanceGuid));

            string token = PrincipalUtil.GetToken(partyId);

            string instancePath = $"/{org}/{app}/instances/{partyId}/{instanceGuid}";

            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            HttpRequestMessage  httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, $"{instancePath}/process/next");
            HttpResponseMessage response           = await client.SendAsync(httpRequestMessage);

            if (!response.IsSuccessStatusCode)
            {
                Assert.True(false, "The next request failed.");
            }

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            //// Commented out the Asserts as another test might clear the Requests list and then fail these
            ////Assert.Equal("app.instance.process.completed", EventsMockSI.Requests.First().eventType);
            ////Assert.NotNull(EventsMockSI.Requests.First().instance);

            TestDataUtil.DeleteInstanceAndData(org, app, partyId, new Guid(instanceGuid));
        }
Ejemplo n.º 30
0
        public async Task GetPageOrder_CustomConfiguration_PageOrderIsRetrievedFromAppAndReturned()
        {
            string        org      = "ttd";
            string        app      = "issue-5740";
            List <string> expected = new List <string> {
                "Side4", "Side2", "Side1", "Side3", "1337"
            };

            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);
            string     token  = PrincipalUtil.GetToken(1337);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpRequestMessage httpRequestMessage =
                new HttpRequestMessage(HttpMethod.Post, $"/{org}/{app}/instances/1001/26133fb5-a9f2-45d4-90b1-f6d93ad40713/pages/order?dataTypeId=default");

            httpRequestMessage.Content = new StringContent("{\"skjemanummer\": \"1337\"}", Encoding.UTF8, "application/json");

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            List <string> actual = JsonConvert.DeserializeObject <List <string> >(responseContent);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(expected, actual);
        }