public void PopTokenBuilder_Build_ValidateToken_OAuth2Example_XMLFormat_Success_Test1b() { // Arrange var keyValuePairDictionary = new Dictionary <string, string> { { PopEhtsKeyEnum.Authorization.GetDescription(), "Basic UtKV75JJbVAewOrkHMXhLbiQ11SS" }, { PopEhtsKeyEnum.Uri.GetDescription(), "/oauth2/v6/tokens" }, { PopEhtsKeyEnum.HttpMethod.GetDescription(), PopEhtsKeyEnum.Post.GetDescription() }, }; var hashMapKeyValuePair = HashMapKeyValuePair.Set <string, string>(keyValuePairDictionary); var popTokenBuilder = new PopTokenBuilder(audience, issuer); // Act var popToken = popTokenBuilder.SetEhtsKeyValueMap(hashMapKeyValuePair) .SignWith(_privateRsaKeyXml) // XML format .Build(); var publicRsaSecurityKey = PopTokenBuilderUtils.CreateRsaSecurityKey(_publicRsaKeyXml); // XML format var tokenValidationResult = PopTokenBuilderUtils.ValidateToken(popToken, issuer, audience, publicRsaSecurityKey); // Assert Assert.IsNotNull(popToken); Assert.IsNotNull(tokenValidationResult); Assert.IsTrue(tokenValidationResult.IsValid); Assert.IsTrue(tokenValidationResult.Claims.Count == 9); }
public void PopTokenBuilder_Build_ValidateToken_ApiExample_XmlFormat_Success_Test2b() { // Arrange var keyValuePairDictionary = new Dictionary <string, string> { { PopEhtsKeyEnum.ContentType.GetDescription(), PopEhtsKeyEnum.ApplicationJson.GetDescription() }, { PopEhtsKeyEnum.CacheControl.GetDescription(), PopEhtsKeyEnum.NoCache.GetDescription() }, { PopEhtsKeyEnum.Authorization.GetDescription(), "Bearer UtKV75JJbVAewOrkHMXhLbiQ11SS" }, { PopEhtsKeyEnum.Uri.GetDescription(), "/commerce/v1/orders" }, { PopEhtsKeyEnum.HttpMethod.GetDescription(), PopEhtsKeyEnum.Post.GetDescription() }, { PopEhtsKeyEnum.Body.GetDescription(), "{\"orderId\": 100, \"product\": \"Mobile Phone\"}" } }; var hashMapKeyValuePair = HashMapKeyValuePair.Set <string, string>(keyValuePairDictionary); var popTokenBuilder = new PopTokenBuilder(audience, issuer); // Act var popToken = popTokenBuilder.SetEhtsKeyValueMap(hashMapKeyValuePair) .SignWith(_privateRsaKeyXml) // XML format .Build(); var publicRsaSecurityKey = PopTokenBuilderUtils.CreateRsaSecurityKey(_publicRsaKeyXml); // XML format var tokenValidationResult = PopTokenBuilderUtils.ValidateToken(popToken, issuer, audience, publicRsaSecurityKey); //Assert Assert.IsNotNull(popToken); Assert.IsNotNull(tokenValidationResult); Assert.IsTrue(tokenValidationResult.IsValid); Assert.IsTrue(tokenValidationResult.Claims.Count == 9); }
public void HashMapKeyValuePair_Set_Test() { // Act var hashMapKeyValuePair = HashMapKeyValuePair.Set <string, string>(dictionary); // Assert Assert.IsNotNull(hashMapKeyValuePair); Assert.AreEqual(3, hashMapKeyValuePair.Count); }
public void PopTokenBuilder_Build_EhtsKeyValueMap_GreaterThan100_Test() { // Arrange var popTokenBuilder = new PopTokenBuilder(audience, issuer); var keyValuePairDictionary = new Dictionary <string, string>(); for (var i = 0; i < 101; i++) // Create 101 key value pairs { keyValuePairDictionary.Add(popTokenBuilder.GetUniqueIdentifier(), popTokenBuilder.GetUniqueIdentifier()); } var ehtsKeyValueMap = HashMapKeyValuePair.Set <string, string>(keyValuePairDictionary); // Act popTokenBuilder.SetEhtsKeyValueMap(ehtsKeyValueMap) .SignWith(privateKeyXmlRsa) .Build(); // Assert // Expected: PopTokenBuilderException }
public void PopTokenBuilder_DoesContainAnyEmptyKeysOrValues_KeyIsEmpty_Test() { // Arrange var keyValuePairDictionary = new Dictionary <string, string> { { string.Empty, PopEhtsKeyEnum.ApplicationJson.GetDescription() }, // Key is empty { PopEhtsKeyEnum.Authorization.GetDescription(), "Bearer UtKV75JJbVAewOrkHMXhLbiQ11SS" }, { PopEhtsKeyEnum.Uri.GetDescription(), "/commerce/v1/orders" }, { PopEhtsKeyEnum.HttpMethod.GetDescription(), PopEhtsKeyEnum.Post.GetDescription() }, { PopEhtsKeyEnum.Body.GetDescription(), "{\"orderId\": 100, \"product\": \"Mobile Phone\"}" } }; var hashMapKeyValuePair = HashMapKeyValuePair.Set <string, string>(keyValuePairDictionary); var popTokenBuilder = new PopTokenBuilder(audience, issuer); // Act popTokenBuilder.SetEhtsKeyValueMap(hashMapKeyValuePair) .SignWith(privateKeyXmlRsa) .Build(); // Assert // Expected: PopTokenBuilderException }
public void PopTokenBuilder_Build_Both_RsaSecurityKey_privateKeyXmlRsa_Null_Test() { // Arrange var popTokenBuilder = new PopTokenBuilder(audience, issuer); var keyValuePairDictionary = new Dictionary <string, string>(); for (var i = 0; i < 100; i++) { keyValuePairDictionary.Add(popTokenBuilder.GetUniqueIdentifier(), popTokenBuilder.GetUniqueIdentifier()); } var ehtsKeyValueMap = HashMapKeyValuePair.Set <string, string>(keyValuePairDictionary); _privateRsaKeyPem = null; // privateKeyXmlRsa is null // Act popTokenBuilder.SetEhtsKeyValueMap(ehtsKeyValueMap) .SignWith(_privateRsaKeyPem) .Build(); // Assert // Expected: PopTokenBuilderException }
public void PopTokenBuilder_Build_ValidPopToken_Success_Test() { // Arrange var keyValuePairDictionary = new Dictionary <string, string> { { PopEhtsKeyEnum.ContentType.GetDescription(), PopEhtsKeyEnum.ApplicationJson.GetDescription() }, { PopEhtsKeyEnum.Authorization.GetDescription(), "Bearer UtKV75JJbVAewOrkHMXhLbiQ11SS" }, { PopEhtsKeyEnum.Uri.GetDescription(), "/commerce/v1/orders" }, { PopEhtsKeyEnum.HttpMethod.GetDescription(), PopEhtsKeyEnum.Post.GetDescription() }, { PopEhtsKeyEnum.Body.GetDescription(), "{\"orderId\": 100, \"product\": \"Mobile Phone\"}" } }; var hashMapKeyValuePair = HashMapKeyValuePair.Set <string, string>(keyValuePairDictionary); var popTokenBuilder = new PopTokenBuilder(audience, issuer); // Act var popToken = popTokenBuilder.SetEhtsKeyValueMap(hashMapKeyValuePair) .SignWith(privateKeyXmlRsa) .Build(); // Assert Assert.IsTrue(!string.IsNullOrEmpty(popToken)); }
public void PopTokenBuilder_Build_ValidPopToken_GeneralException_Test() { // Arrange var keyValuePairDictionary = new Dictionary <string, string> { { PopEhtsKeyEnum.ContentType.GetDescription(), PopEhtsKeyEnum.ApplicationJson.GetDescription() }, { PopEhtsKeyEnum.Authorization.GetDescription(), "Bearer UtKV75JJbVAewOrkHMXhLbiQ11SS" }, { PopEhtsKeyEnum.Uri.GetDescription(), "/commerce/v1/orders" }, { PopEhtsKeyEnum.HttpMethod.GetDescription(), PopEhtsKeyEnum.Post.GetDescription() }, { PopEhtsKeyEnum.Body.GetDescription(), "{\"orderId\": 100, \"product\": \"Mobile Phone\"}" } }; var hashMapKeyValuePair = HashMapKeyValuePair.Set <string, string>(keyValuePairDictionary); var popTokenBuilder = new PopTokenBuilder(audience, issuer); privateKeyXmlRsa = privateKeyPemRsa; // Use Pem format rather then XML format // Act popTokenBuilder.SetEhtsKeyValueMap(hashMapKeyValuePair) .SignWith(privateKeyXmlRsa) .Build(); // Assert // Expected: PopTokenBuilderException }