private ConditionResult assertCondition(IfElement condition) { ConditionResult _assertResult = null; string valueOF = condition.getAttribute(AttributeConstants.VALUE_OF).getValue().ToString(); object expectedValue = condition.getAttribute(AttributeConstants.VALUE).getValue(); string conditionType = condition.getAttribute(AttributeConstants.CONDITION).getValue().ToString(); object valueToCheck = this._AttributeSelector.valueOf(valueOF); if (valueToCheck == null) { throw new Exception("Could not assert [null] value-of."); } try { ConditionType _condition = EnumUtil.Parse <ConditionType>(conditionType); _assertResult = new ConditionResult( AssertionUtil.AssertCondition(_condition, expectedValue, valueToCheck), condition.DoNodes, condition.ElseNodes); } catch (Exception ex) { throw ex; } return(_assertResult); }
public async Task GetResourcePoliciesFromXacmlPolicies_NoOrg_TC08() { // Arrange Stream dataStream = File.OpenRead("Data/Json/GetResourcePolicies/SKDMissingOrgRequest.json"); StreamContent content = new StreamContent(dataStream); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); List <ResourcePolicyResponse> expectedResourcePolicyResponses = new List <ResourcePolicyResponse> { new ResourcePolicyResponse { AppId = new List <AttributeMatch> { new AttributeMatch { Id = XacmlRequestAttribute.AppAttribute, Value = "TaxReport2" } }, ErrorResponse = "Organisation must be defined in the path" } }; // Act HttpResponseMessage response = await _client.PostAsync("authorization/api/v1/policies/GetPolicies", content); string responseContent = await response.Content.ReadAsStringAsync(); List <ResourcePolicyResponse> actualResourcePolicyResponses = JsonConvert.DeserializeObject <List <ResourcePolicyResponse> >(responseContent); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); AssertionUtil.AssertCollections(expectedResourcePolicyResponses, actualResourcePolicyResponses, AssertionUtil.AssertResourcePolicyResponseEqual); }
public void ThrowsExceptionWhenAttributeStatementHasInvalidStatementType() { // Arrange var validator = new DKSaml20AssertionValidator(AssertionUtil.GetAudiences(), false); var saml20Assertion = AssertionUtil.GetBasicAssertion(); var authzDecisionStatement = new AuthzDecisionStatement { Decision = DecisionType.Permit, Resource = "http://safewhere.net", Action = new[] { new Action() } }; authzDecisionStatement.Action[0].Namespace = "http://actionns.com"; authzDecisionStatement.Action[0].Value = "value"; var statements = new List <StatementAbstract>(saml20Assertion.Items) { authzDecisionStatement }; saml20Assertion.Items = statements.ToArray(); // Act validator.ValidateAssertion(saml20Assertion); }
public async Task ContextHandler_TC06() { // Arrange string testCase = "AltinnApps0006"; XacmlContextRequest request = TestSetupUtil.CreateXacmlContextRequest(testCase); XacmlContextRequest expectedEnrichedRequest = TestSetupUtil.GetEnrichedRequest(testCase); // Act Instance instance = TestSetupUtil.GetInstanceData("26133fb5-a9f2-45d4-90b1-f6d93ad40713.json"); List <Role> roles = TestSetupUtil.GetRoles(1, 1000); _policyInformationRepositoryMock.Setup(p => p.GetInstance(It.Is <string>(s => s.Equals("1000/26133fb5-a9f2-45d4-90b1-f6d93ad40713")))).ReturnsAsync(instance); _rolesMock.Setup(p => p.GetDecisionPointRolesForUser(It.Is <int>(s => s.Equals(1)), It.Is <int>(p => p.Equals(1000)))).ReturnsAsync(roles); XacmlContextRequest enrichedRequest = await _contextHandler.Enrich(request); var a = JsonConvert.SerializeObject(enrichedRequest); var b = JsonConvert.SerializeObject(expectedEnrichedRequest); // Assert Assert.NotNull(enrichedRequest); Assert.NotNull(expectedEnrichedRequest); AssertionUtil.AssertEqual(expectedEnrichedRequest, enrichedRequest); }
public void SerializedXACMLPolicy_ShouldBeEqual() { XmlDocument policyDocument = new XmlDocument(); policyDocument.Load(Path.Combine(GetAltinnAppsPath(), "AltinnApps0001Policy.xml")); XacmlPolicy originalPolicy; using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml))) { originalPolicy = XacmlParser.ParseXacmlPolicy(reader); } MemoryStream dataStream = new MemoryStream(); XmlWriter writer = XmlWriter.Create(dataStream); XacmlSerializer.WritePolicy(writer, originalPolicy); writer.Flush(); dataStream.Position = 0; XacmlPolicy serializedPolicy; using (XmlReader reader = XmlReader.Create(dataStream)) { serializedPolicy = XacmlParser.ParseXacmlPolicy(reader); } AssertionUtil.AssertPolicyEqual(originalPolicy, serializedPolicy); }
public void ValidatesAudienceRestrictionWithSeveralAudiences() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); var validator = new Saml20AssertionValidator(AssertionUtil.GetAudiences(), false); foreach (var audienceCondition in assertion.Conditions.Items) { if (!(audienceCondition is AudienceRestriction)) { continue; } var audienceRestriction = (AudienceRestriction)audienceCondition; var audiences = new List <string>(audienceRestriction.Audience) { "http://well/formed.uri" }; audienceRestriction.Audience = audiences; break; } // Act validator.ValidateAssertion(assertion); }
// TODO: test private void executeWhile(WhileElement whileNode) { string valueOF = whileNode.getAttribute(AttributeConstants.VALUE_OF).getValue().ToString(); object expectedValue = whileNode.getAttribute(AttributeConstants.VALUE).getValue(); string conditionType = whileNode.getAttribute(AttributeConstants.CONDITION).getValue().ToString(); object valueToCheck = this._AttributeSelector.valueOf(valueOF); if (valueToCheck == null) { throw new Exception("Could not assert [null] value-of."); } try { ConditionType _condition = EnumUtil.Parse <ConditionType>(conditionType); while (AssertionUtil.AssertCondition(_condition, expectedValue, valueToCheck)) { if (whileNode.hasDoNodes()) { runRecursive(whileNode.DoNodes); } } } catch (Exception ex) { throw ex; } }
public void ThenImageIsNotChanged_() { AssertionUtil.AssertTrue( ImageUtil.ImageCompareString( (Bitmap)ScenarioContext.Current["initialImage"], new Bitmap(Image.FromFile(Path.Combine((string)ScenarioContext.Current["imagePath"]))) ), "Image has changed"); }
public void ValidatesAssertion() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); var validator = new Saml20AssertionValidator(AssertionUtil.GetAudiences(), false); // Act validator.ValidateAssertion(assertion); }
public void ThrowsExceptionWhenAudienceRestrictionIsNotConfigured() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); var validator = new Saml20AssertionValidator(null, false); // Act validator.ValidateAssertion(assertion); }
public void AssertFieldValueIsCorrect(string field, string value) { switch (field) { case "Search in": AssertionUtil.AssertEquals(value, FindFilesView.TextBoxSearchIn.Name, "Search in field value is incorrect"); break; } }
public void ThrowsExceptionWhenAudienceRestrictionIsNotConfigured() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); var validator = new Saml20AssertionValidator(null, false); // Act Assert.Throws <Saml20FormatException>(() => validator.ValidateAssertion(assertion), "The service is not configured to meet any audience restrictions"); }
public void PDP_AuthorizeAccess_IIA007() { bool contextRequstIsEnriched = false; string testCase = "IIA007"; XacmlContextResponse contextResponeExpected = XacmlTestDataParser.ParseResponse(testCase + "Response.xml", GetConformancePath()); XacmlContextResponse xacmlResponse = SetuUpPolicyDecisionPoint(testCase, contextRequstIsEnriched); AssertionUtil.AssertEqual(contextResponeExpected, xacmlResponse); }
public void PDP_AuthorizeAccess_AltinnApps0003() { bool contextRequstIsEnriched = true; string testCase = "AltinnApps0003"; XacmlContextResponse contextResponeExpected = XacmlTestDataParser.ParseResponse(testCase + "Response.xml", GetAltinnAppsPath()); XacmlContextResponse xacmlResponse = SetuUpPolicyDecisionPoint(testCase, contextRequstIsEnriched); AssertionUtil.AssertEqual(contextResponeExpected, xacmlResponse); }
public void ValidatesSubjectConfirmation() { // Arrange var validator = new DKSaml20SubjectConfirmationValidator(); var saml20Assertion = AssertionUtil.GetBasicAssertion(); var subjectConfirmation = (SubjectConfirmation)Array.Find(saml20Assertion.Subject.Items, item => item is SubjectConfirmation); // Act validator.ValidateSubjectConfirmation(subjectConfirmation); }
public void ValidatesTimeRestrictionBothNotBeforeAndNotOnOrAfter() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); var validator = new Saml20AssertionValidator(AssertionUtil.GetAudiences(), false); assertion.Conditions.NotBefore = DateTime.UtcNow.AddDays(-1); assertion.Conditions.NotOnOrAfter = DateTime.UtcNow.AddDays(1); // Act validator.ValidateAssertion(assertion); }
public void AssertFolderIsOpenInPanel(Table table) { Scope.DefaultWindow = Scope.Application.Application.GetWindow(ConfigurationManager.AppSettings["MainWindowName"]); foreach (var row in table.Rows) { var folderPath = row["Folder path"]; var panel = row["Panel"]; MainView.ListBoxPanel(PanelBl.GetPanelIndex(panel)).Click(); AssertionUtil.AssertNotNull(MainView.PanelCurrentDirectory(folderPath), "Current panel directory is incorrect"); } }
public void ThrowsExceptionWhenIssuerFormatInvalid() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); assertion.Issuer.Format = "a non wellformed uri"; var validator = new Saml20AssertionValidator(AssertionUtil.GetAudiences(), false); // Act validator.ValidateAssertion(assertion); }
//ExpectedMessage = "The service is not configured to meet any audience restrictions" public void ThrowsExceptionWhenAudienceRestrictionIsNotConfigured() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); var validator = new Saml20AssertionValidator(null, false); // Act Assert.Throws(typeof(Saml20FormatException), () => { validator.ValidateAssertion(assertion, true); }); }
public void AssertWarningWindowIsClosed() { List <string> titles = new List <string>(); foreach (var modal in Scope.DefaultWindow.ModalWindows()) { titles.Add(modal.Title); } AssertionUtil.AssertFalse(titles.Contains(ConfigurationManager.AppSettings["ModalWindowName"]), "Modal window is found when should not"); }
public void ThrowsExceptionWhenSubjectConfirmationDoesNotContainSubject() { // Arrange var saml20Assertion = AssertionUtil.GetBasicAssertion(); saml20Assertion.Subject.Items = new object[] { }; var validator = new Saml20SubjectValidator(); // Act validator.ValidateSubject(saml20Assertion.Subject); }
public void ThrowsExceptionWhenSubjectConfirmationContainsElementsOfWrongIdentifier() { // Arrange var saml20Assertion = AssertionUtil.GetBasicAssertion(); saml20Assertion.Subject.Items = new object[] { string.Empty, 24, new List <object>(1), new Advice() }; var validator = new Saml20SubjectValidator(); // Act validator.ValidateSubject(saml20Assertion.Subject); }
public void ThrowsExceptionWhenWrongVersion() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); assertion.Version = "60"; var validator = new Saml20AssertionValidator(AssertionUtil.GetAudiences(), false); // Act Assert.Throws <Saml20FormatException>(() => validator.ValidateAssertion(assertion), "Wrong value of version attribute on Assertion element"); }
public void ThrowsExceptionWhenIssuerNull() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); assertion.Issuer = null; var validator = new Saml20AssertionValidator(AssertionUtil.GetAudiences(), false); // Act Assert.Throws <Saml20FormatException>(() => validator.ValidateAssertion(assertion), "Assertion element must have an issuer element."); }
public void ValidatesTimeRestrictionNotSpecified() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); var validator = new Saml20AssertionValidator(AssertionUtil.GetAudiences(), false); assertion.Conditions.NotBefore = null; assertion.Conditions.NotOnOrAfter = null; // Act validator.ValidateAssertion(assertion); }
public void ThrowsExceptionWhenIssuerFormatInvalid() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); assertion.Issuer.Format = "a non wellformed uri"; var validator = new Saml20AssertionValidator(AssertionUtil.GetAudiences(), false); // Act Assert.Throws <Saml20FormatException>(() => validator.ValidateAssertion(assertion), "NameID element has Format attribute which is not a wellformed absolute uri."); }
public void ThrowsExceptionWhenIssuerNull() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); assertion.Issuer = null; var validator = new Saml20AssertionValidator(AssertionUtil.GetAudiences(), false); // Act validator.ValidateAssertion(assertion); }
public void ThrowsExceptionWhenWrongVersion() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); assertion.Version = "60"; var validator = new Saml20AssertionValidator(AssertionUtil.GetAudiences(), false); // Act validator.ValidateAssertion(assertion); }
public async Task PDP_Decision_AltinnApps0005() { string testCase = "AltinnApps0005"; HttpClient client = GetTestClient(); HttpRequestMessage httpRequestMessage = TestSetupUtil.CreateXacmlRequest(testCase); XacmlContextResponse expected = TestSetupUtil.ReadExpectedResponse(testCase); // Act XacmlContextResponse contextResponse = await TestSetupUtil.GetXacmlContextResponseAsync(client, httpRequestMessage); // Assert AssertionUtil.AssertEqual(expected, contextResponse); }
public void ValidatesTimeRestrictionNotOnOrAfterTomorrow() { // Arrange var assertion = AssertionUtil.GetBasicAssertion(); var validator = new Saml20AssertionValidator(AssertionUtil.GetAudiences(), false); // Test with NotOnOrAfter that post-dates now assertion.Conditions.NotBefore = null; assertion.Conditions.NotOnOrAfter = DateTime.UtcNow.AddDays(1); // Act validator.ValidateAssertion(assertion); }