public void NationalityShouldBeAddedToProfile() { var attribute = new ProtoBuf.Attribute.Attribute { Name = Constants.UserProfile.NationalityAttribute, ContentType = ContentType.String, Value = _byteStringValue }; _yotiProfile = TestTools.Profile.CreateUserProfileWithSingleAttribute <string>(attribute); Assert.AreEqual(_yotiProfile.Nationality.GetValue(), StringValue); }
public void AddressShouldBeAddedToProfile() { var attribute = new ProtoBuf.Attribute.Attribute { Name = Constants.UserProfile.PostalAddressAttribute, ContentType = ContentType.String, Value = _byteStringValue }; _yotiProfile = TestTools.Profile.CreateUserProfileWithSingleAttribute <string>(attribute); Assert.AreEqual(StringValue, _yotiProfile.Address.GetValue()); }
private static AttributeList CreateAttributeListWithSingleAttribute(string name, ContentType contentType, ByteString byteStringValue) { var attribute = new ProtoBuf.Attribute.Attribute { Name = name, ContentType = contentType, Value = byteStringValue }; return(new AttributeList { Attributes = { attribute } }); }
public void DateOfBirthShouldBeAddedToProfile() { var attribute = new ProtoBuf.Attribute.Attribute { Name = Constants.UserProfile.DateOfBirthAttribute, ContentType = ContentType.Date, Value = ByteString.CopyFromUtf8(DateOfBirthString) }; _yotiProfile = TestTools.Profile.CreateUserProfileWithSingleAttribute <DateTime>(attribute); Assert.IsInstanceOfType(_yotiProfile.DateOfBirth.GetValue(), typeof(DateTime)); Assert.AreEqual(_yotiProfile.DateOfBirth.GetValue(), DateOfBirthValue); }
public static BaseAttribute ConvertToBaseAttribute(ProtoBuf.Attribute.Attribute attribute) { NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); if (attribute.ContentType != ContentType.String && attribute.Value.Length == 0) { throw new InvalidOperationException(Properties.Resources.EmptyValueInvalid); } byte[] byteAttributeValue = attribute.Value.ToByteArray(); return(CreateYotiAttribute(attribute, logger, byteAttributeValue)); }
public void NewContentTypeShouldBeRetrieved() { string name = "newType"; var attribute = new ProtoBuf.Attribute.Attribute { Name = name, ContentType = (ContentType)99, Value = _byteStringValue }; _yotiProfile = TestTools.Profile.CreateUserProfileWithSingleAttribute <string>(attribute); Assert.AreEqual(StringValue, _yotiProfile.GetAttributeByName <string>(name).GetValue().ToString()); Assert.AreEqual(StringValue, _yotiProfile.GetAttributesByName <string>(name).Single().GetValue().ToString()); }
public void DrivingLicenseShouldBeAddedToAttribute() { ProtoBuf.Attribute.Attribute attribute = TestTools.Anchors.BuildAnchoredAttribute( Constants.UserProfile.StructuredPostalAddressAttribute, "{ \"properties\": { \"name\": { \"type\": \"string\"} } }", ProtoBuf.Attribute.ContentType.Json, TestAnchors.DrivingLicenseAnchor); _yotiProfile = TestTools.Profile.AddAttributeToProfile <Dictionary <string, JToken> >(new YotiProfile(), attribute); IEnumerable <Anchor> sources = _yotiProfile.StructuredPostalAddress.GetSources(); Assert.IsTrue( sources.Any( s => s.GetValue() == DrivingLicenseSourceType)); }
public void YotiAdminShouldBeAddedToAttribute() { ProtoBuf.Attribute.Attribute attribute = TestTools.Anchors.BuildAnchoredAttribute( Constants.UserProfile.SelfieAttribute, StringValue, ProtoBuf.Attribute.ContentType.Jpeg, TestAnchors.YotiAdminAnchor); _yotiProfile = TestTools.Profile.AddAttributeToProfile <Image>(new YotiProfile(), attribute); IEnumerable <Anchor> verifiers = _yotiProfile.Selfie.GetVerifiers(); Assert.IsTrue( verifiers.Any( s => s.GetValue() == YotiAdminVerifierType)); }
public void PassportShouldBeAddedToAttribute() { ProtoBuf.Attribute.Attribute attribute = TestTools.Anchors.BuildAnchoredAttribute( Constants.UserProfile.DateOfBirthAttribute, DateOfBirthString, ProtoBuf.Attribute.ContentType.Date, TestAnchors.PassportAnchor); _yotiProfile = TestTools.Profile.AddAttributeToProfile <DateTime>(new YotiProfile(), attribute); IEnumerable <Anchor> sources = _yotiProfile.DateOfBirth.GetSources(); Assert.IsTrue( sources.Any( s => s.GetValue() == PassportSourceType)); }
public void JpegSelfieShouldBeAddedToProfile() { var attribute = new ProtoBuf.Attribute.Attribute { Name = Constants.UserProfile.SelfieAttribute, ContentType = ContentType.Jpeg, Value = _byteStringValue }; _yotiProfile = TestTools.Profile.CreateUserProfileWithSingleAttribute <Image>(attribute); Assert.AreEqual("image/jpeg", _yotiProfile.Selfie.GetValue().GetMIMEType()); Assert.AreEqual( "data:image/jpeg;base64," + Conversion.BytesToBase64(Encoding.UTF8.GetBytes(StringValue)), _yotiProfile.Selfie.GetValue().GetBase64URI()); Assert.IsNotNull(_yotiProfile.Selfie.GetValue()); }
public void UnknownAnchorShouldHaveCorrectValues() { ProtoBuf.Attribute.Attribute attribute = TestTools.Anchors.BuildAnchoredAttribute( Constants.UserProfile.NationalityAttribute, "LND", ProtoBuf.Attribute.ContentType.String, TestAnchors.UnknownAnchor); ProtoBuf.Attribute.Anchor protobufAnchor = attribute.Anchors.Single(); var yotiAnchor = new Anchor(protobufAnchor); Assert.AreEqual(AnchorType.UNKNOWN, yotiAnchor.GetAnchorType()); Assert.AreEqual("", yotiAnchor.GetValue()); Assert.AreEqual("TEST UNKNOWN SUB TYPE", yotiAnchor.GetSubType()); Assert.AreEqual(636873795118400370, yotiAnchor.GetSignedTimeStamp().GetTimestamp().Ticks); Assert.AreEqual("00ABA6DD34D84D2696171C6E856E952C81", yotiAnchor.GetOriginServerCerts().First().SerialNumber); }
public void AddressShouldNotBeTakenFromFormattedAddressIfAddressIsPresent() { const string addressFormat = "1"; const string buildingNumber = "15a"; const string addressLineOne = "15a North Street"; const string townCity = "CARSHALTON"; const string postalCode = "SM5 2HW"; const string countryIso = "GBR"; const string country = "UK"; const string formattedAddress = "15a North Street\nCARSHALTON\nSM5 2HW\nUK"; const string postalAddress = "33a South Street\nCARSHALTON\nSM5 2HW\nUK"; const string structuredAddressString = "{ \"" + AddressFormatJson + "\": " + addressFormat + ", \"" + BuildingNumberJson + "\": \"" + buildingNumber + "\", \"" + AddressLineOneJson + "\": \"" + addressLineOne + "\", \"" + TownCityJson + "\": \"" + townCity + "\", \"" + PostalCodeJson + "\": \"" + postalCode + "\", \"" + CountryIsoJson + "\": \"" + countryIso + "\", \"" + CountryJson + "\": \"" + country + "\", \"" + FormattedAddressJson + "\": \"" + formattedAddress + "\" }"; var structuredAddressAttribute = new ProtoBuf.Attribute.Attribute { Name = Constants.UserProfile.StructuredPostalAddressAttribute, ContentType = ContentType.Json, Value = ByteString.CopyFromUtf8(structuredAddressString) }; var addressAttribute = new ProtoBuf.Attribute.Attribute { Name = Constants.UserProfile.PostalAddressAttribute, ContentType = ContentType.String, Value = ByteString.CopyFromUtf8(postalAddress) }; _yotiProfile = TestTools.Profile.CreateUserProfileWithSingleAttribute <Dictionary <string, JToken> >(structuredAddressAttribute); _yotiProfile = TestTools.Profile.AddAttributeToProfile <string>(_yotiProfile, addressAttribute); ActivityDetailsParser.SetAddressToBeFormattedAddressIfNull(_yotiProfile); Assert.AreNotEqual(_yotiProfile.Address.GetValue(), formattedAddress); }
public void UKStructuredPostalAddressShouldBeAddedToProfile() { const string addressFormat = "1"; const string buildingNumber = "15a"; const string addressLineOne = "15a North Street"; const string townCity = "CARSHALTON"; const string postalCode = "SM5 2HW"; const string countryIso = "GBR"; const string country = "UK"; const string formattedAddress = "15a North Street\nCARSHALTON\nSM5 2HW\nUK"; const string addressString = "{ \"" + AddressFormatJson + "\": " + addressFormat + ", \"" + BuildingNumberJson + "\": \"" + buildingNumber + "\", \"" + AddressLineOneJson + "\": \"" + addressLineOne + "\", \"" + TownCityJson + "\": \"" + townCity + "\", \"" + PostalCodeJson + "\": \"" + postalCode + "\", \"" + CountryIsoJson + "\": \"" + countryIso + "\", \"" + CountryJson + "\": \"" + country + "\", \"" + FormattedAddressJson + "\": \"" + formattedAddress + "\" }"; var attribute = new ProtoBuf.Attribute.Attribute { Name = Constants.UserProfile.StructuredPostalAddressAttribute, ContentType = ContentType.Json, Value = ByteString.CopyFromUtf8(addressString) }; _yotiProfile = TestTools.Profile.CreateUserProfileWithSingleAttribute <Dictionary <string, JToken> >(attribute); Dictionary <string, JToken> structuredPostalAddress = _yotiProfile.StructuredPostalAddress.GetValue(); AssertDictionaryValue(addressFormat, AddressFormatJson, structuredPostalAddress); AssertDictionaryValue(buildingNumber, BuildingNumberJson, structuredPostalAddress); AssertDictionaryValue(addressLineOne, AddressLineOneJson, structuredPostalAddress); AssertDictionaryValue(townCity, TownCityJson, structuredPostalAddress); AssertDictionaryValue(postalCode, PostalCodeJson, structuredPostalAddress); AssertDictionaryValue(countryIso, CountryIsoJson, structuredPostalAddress); AssertDictionaryValue(country, CountryJson, structuredPostalAddress); AssertDictionaryValue(formattedAddress, FormattedAddressJson, structuredPostalAddress); }
public void USAStructuredPostalAddressShouldBeAddedToProfile() { const string addressFormat = "3"; const string addressLineOne = "1512 Ferry Street"; const string townCity = "Anniston"; const string state = "AL"; const string postalCode = "36201"; const string countryIso = "USA"; const string country = "USA"; const string formattedAddress = "1512 Ferry Street\nAnniston AL 36201\nUSA"; const string addressString = "{ \"" + AddressFormatJson + "\": " + addressFormat + ", \"" + AddressLineOneJson + "\": \"" + addressLineOne + "\", \"" + TownCityJson + "\": \"" + townCity + "\", \"" + StateJson + "\": \"" + state + "\", \"" + PostalCodeJson + "\": \"" + postalCode + "\", \"" + CountryIsoJson + "\": \"" + countryIso + "\", \"" + CountryJson + "\": \"" + country + "\", \"" + FormattedAddressJson + "\": \"" + formattedAddress + "\" }"; var attribute = new ProtoBuf.Attribute.Attribute { Name = Constants.UserProfile.StructuredPostalAddressAttribute, ContentType = ContentType.Json, Value = ByteString.CopyFromUtf8(addressString) }; _yotiProfile = TestTools.Profile.CreateUserProfileWithSingleAttribute <Dictionary <string, JToken> >(attribute); Dictionary <string, JToken> structuredPostalAddress = _yotiProfile.StructuredPostalAddress.GetValue(); AssertDictionaryValue(addressFormat, AddressFormatJson, structuredPostalAddress); AssertDictionaryValue(addressLineOne, AddressLineOneJson, structuredPostalAddress); AssertDictionaryValue(townCity, TownCityJson, structuredPostalAddress); AssertDictionaryValue(state, StateJson, structuredPostalAddress); AssertDictionaryValue(postalCode, PostalCodeJson, structuredPostalAddress); AssertDictionaryValue(countryIso, CountryIsoJson, structuredPostalAddress); AssertDictionaryValue(country, CountryJson, structuredPostalAddress); AssertDictionaryValue(formattedAddress, FormattedAddressJson, structuredPostalAddress); }
public static ProtoBuf.Attribute.Attribute CreateMultiValueAttribute(string multiValueAttributeName, ContentType innerContentType, ByteString value) { var outerValue = new MultiValue.Types.Value { ContentType = innerContentType, Data = value }; var multiValue = new MultiValue(); multiValue.Values.Add(outerValue); var attribute = new ProtoBuf.Attribute.Attribute { Name = multiValueAttributeName, ContentType = ContentType.MultiValue, Value = multiValue.ToByteString() }; return(attribute); }
public void FailureInAttributeParsingShouldNotStopOtherAttributes() { string jsonValue = "{}"; ByteString byteJsonValue = ByteString.CopyFromUtf8(jsonValue); string attribute1Name = "attribute1"; string attribute2Name = "attribute2"; ProtoBuf.Attribute.Attribute attribute1 = CreateProtobufAttribute(attribute1Name, byteJsonValue, ContentType.Json); ProtoBuf.Attribute.Attribute invalidAttribute = CreateProtobufAttribute("invalidAttribute", ByteString.CopyFromUtf8("invalid"), ContentType.Json); ProtoBuf.Attribute.Attribute attribute2 = CreateProtobufAttribute(attribute2Name, byteJsonValue, ContentType.Json); var attributeList = new ProtoBuf.Attribute.AttributeList { Attributes = { attribute1, invalidAttribute, attribute2 } }; var result = AttributeConverter.ConvertToBaseAttributes(attributeList); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Any(dict => dict.Value.Any(a => a.GetName() == attribute1Name))); Assert.IsTrue(result.Any(dict => dict.Value.Any(a => a.GetName() == attribute2Name))); }
public void IdentityProfileReportAttributeShouldBeAddedToProfile() { string json; using (StreamReader r = File.OpenText("TestData/RTWIdentityProfileReport.json")) { json = r.ReadToEnd(); } var attribute = new ProtoBuf.Attribute.Attribute { Name = Constants.UserProfile.IdentityProfileReportAttribute, ContentType = ContentType.Json, Value = ByteString.CopyFromUtf8(json) }; _yotiProfile = TestTools.Profile.CreateUserProfileWithSingleAttribute <Dictionary <string, JToken> >(attribute); Dictionary <string, JToken> identityProfileReport = _yotiProfile.IdentityProfileReport.GetValue(); AssertDictionaryValue("<signature provided here>", "proof", identityProfileReport); }
public void ShouldAddMultipleSameNamedAttributes() { string name = "sameName"; var attribute1 = new ProtoBuf.Attribute.Attribute { Name = name, ContentType = ContentType.String, Value = _emptyByteStringValue, EphemeralId = _id1 }; var attribute2 = new ProtoBuf.Attribute.Attribute { Name = name, ContentType = ContentType.String, Value = _emptyByteStringValue, EphemeralId = _id2 }; AttributeList attributeList = new AttributeList { Attributes = { attribute1, attribute2 } }; Dictionary <string, List <BaseAttribute> > convertedAttributeNameDictionary = AttributeConverter.ConvertToBaseAttributes(attributeList); Assert.AreEqual(1, convertedAttributeNameDictionary.Count); List <BaseAttribute> attributes = convertedAttributeNameDictionary.First().Value; Assert.AreEqual(2, attributes.Count); Assert.AreEqual(name, attributes[0].GetName()); Assert.AreEqual(name, attributes[1].GetName()); Assert.AreEqual(_id1, attributes[0].GetId()); Assert.AreEqual(_id2, attributes[1].GetId()); }
private static BaseAttribute CreateYotiAttribute(ProtoBuf.Attribute.Attribute attribute, NLog.Logger logger, byte[] byteAttributeValue) { object value = ParseAttributeValue(attribute.ContentType, logger, byteAttributeValue); string id = attribute.EphemeralId; switch (attribute.ContentType) { case ContentType.String: if (attribute.Name == Constants.UserProfile.DocumentDetailsAttribute) { DocumentDetails documementDetails = DocumentDetailsAttributeParser.ParseFrom((string)value); return(new YotiAttribute <DocumentDetails>( attribute.Name, documementDetails, ParseAnchors(attribute), id)); } return(new YotiAttribute <string>( attribute.Name, (string)value, ParseAnchors(attribute), id)); case ContentType.Date: return(new YotiAttribute <DateTime>( attribute.Name, (DateTime)value, ParseAnchors(attribute), id)); case ContentType.Jpeg: return(new YotiAttribute <Image>( attribute.Name, (JpegImage)value, ParseAnchors(attribute), id)); case ContentType.Png: return(new YotiAttribute <Image>( attribute.Name, (PngImage)value, ParseAnchors(attribute), id)); case ContentType.Json: return(new YotiAttribute <Dictionary <string, JToken> >( attribute.Name, (Dictionary <string, JToken>)value, ParseAnchors(attribute), id)); case ContentType.MultiValue: var multiValueList = (List <MultiValueItem>)value; if (attribute.Name == Constants.UserProfile.DocumentImagesAttribute) { return(new YotiAttribute <List <Image> >( attribute.Name, value: CreateImageListFromMultiValue(multiValueList), ParseAnchors(attribute), id)); } return(new YotiAttribute <List <MultiValueItem> >( attribute.Name, multiValueList, ParseAnchors(attribute), id)); case ContentType.Int: return(new YotiAttribute <int>( attribute.Name, (int)value, ParseAnchors(attribute), id)); default: logger.Warn($"Unknown content type {attribute.ContentType}, attempting to parse it as a string"); return(new YotiAttribute <string>( attribute.Name, Conversion.BytesToUtf8(byteAttributeValue), ParseAnchors(attribute), id)); } }
public static YotiProfile CreateUserProfileWithSingleAttribute <T>(ProtoBuf.Attribute.Attribute attribute) { return(AddAttributeToProfile <T>(new YotiProfile(), attribute)); }
public void NestedJSONStructuredPostalAddressShouldBeAddedToProfile() { object nestedValueObject; using (StreamReader r = File.OpenText("TestData/NestedJSON.json")) { string json = r.ReadToEnd(); nestedValueObject = Newtonsoft.Json.JsonConvert.DeserializeObject(json); } const string addressFormat = "1"; const string buildingNumber = "15a"; const string addressLineOne = "15a North Street"; const string townCity = "CARSHALTON"; const string postalCode = "SM5 2HW"; const string countryIso = "GBR"; const string country = "UK"; const string formattedAddress = "15a North Street\nCARSHALTON\nSM5 2HW\nUK"; const string nestedValueJson = "nested_value"; const string oneJson = "1"; const string oneTwoJson = "1-2"; const string oneTwoFiveJson = "1-2-5"; const string oneTwoFiveOneJson = "1-2-5-1"; const string oneTwoFiveOneJsonValue = "OneTwoFiveOne"; string addressString = "{ \"" + AddressFormatJson + "\": " + addressFormat + ", \"" + BuildingNumberJson + "\": \"" + buildingNumber + "\", \"" + AddressLineOneJson + "\": \"" + addressLineOne + "\", \"" + TownCityJson + "\": \"" + townCity + "\", \"" + PostalCodeJson + "\": \"" + postalCode + "\", \"" + CountryIsoJson + "\": \"" + countryIso + "\", \"" + CountryJson + "\": \"" + country + "\", \"" + nestedValueJson + "\": " + nestedValueObject + ", \"" + FormattedAddressJson + "\": \"" + formattedAddress + "\" }"; var attribute = new ProtoBuf.Attribute.Attribute { Name = Constants.UserProfile.StructuredPostalAddressAttribute, ContentType = ContentType.Json, Value = ByteString.CopyFromUtf8(addressString) }; _yotiProfile = TestTools.Profile.CreateUserProfileWithSingleAttribute <Dictionary <string, JToken> >(attribute); Dictionary <string, JToken> structuredPostalAddress = _yotiProfile.StructuredPostalAddress.GetValue(); AssertDictionaryValue(addressFormat, AddressFormatJson, structuredPostalAddress); AssertDictionaryValue(buildingNumber, BuildingNumberJson, structuredPostalAddress); AssertDictionaryValue(addressLineOne, AddressLineOneJson, structuredPostalAddress); AssertDictionaryValue(townCity, TownCityJson, structuredPostalAddress); AssertDictionaryValue(postalCode, PostalCodeJson, structuredPostalAddress); AssertDictionaryValue(countryIso, CountryIsoJson, structuredPostalAddress); AssertDictionaryValue(country, CountryJson, structuredPostalAddress); JToken nestedJsonObj = structuredPostalAddress[nestedValueJson]; JToken token1 = nestedJsonObj[oneJson]; JToken token1_2 = token1[oneTwoJson]; JToken token1_2_5 = token1_2[oneTwoFiveJson]; JToken token1_2_5_1 = token1_2_5[oneTwoFiveOneJson]; Assert.AreEqual(oneTwoFiveOneJsonValue, token1_2_5_1); AssertDictionaryValue(nestedValueObject.ToString(), nestedValueJson, structuredPostalAddress); AssertDictionaryValue(formattedAddress, FormattedAddressJson, structuredPostalAddress); }