Commit e42904e3 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Add test for attribute candidate searching

parent e0f77546
......@@ -80,8 +80,11 @@ func (al *AttributeList) Strings() []string {
}
func (al *AttributeList) Attribute(identifier AttributeTypeIdentifier) string {
if al.CredentialType().Identifier() != identifier.CredentialTypeIdentifier() {
return ""
}
for i, desc := range al.CredentialType().Attributes {
if desc.ID == string(identifier.String()) {
if desc.ID == string(identifier.Name()) {
return al.Strings()[i]
}
}
......
......@@ -199,3 +199,39 @@ func TestAttributeDisjunctionMarshaling(t *testing.T) {
disjunction.selected = &disjunction.Attributes[0]
require.True(t, disjunction.Satisfied())
}
func TestCandidates(t *testing.T) {
parseMetaStore(t)
parseStorage(t)
parseAndroidStorage(t)
attrtype := NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
disjunction := &AttributeDisjunction{
Attributes: []AttributeTypeIdentifier{attrtype},
}
attrs := Manager.Candidates(disjunction)
require.NotNil(t, attrs)
require.Len(t, attrs, 1)
attr := attrs[0]
require.NotNil(t, attr)
require.Equal(t, attr.Type, attrtype)
disjunction = &AttributeDisjunction{
Attributes: []AttributeTypeIdentifier{attrtype},
Values: map[AttributeTypeIdentifier]string{attrtype: "s1234567"},
}
attrs = Manager.Candidates(disjunction)
require.NotNil(t, attrs)
require.Len(t, attrs, 1)
disjunction = &AttributeDisjunction{
Attributes: []AttributeTypeIdentifier{attrtype},
Values: map[AttributeTypeIdentifier]string{attrtype: "foobarbaz"},
}
attrs = Manager.Candidates(disjunction)
require.NotNil(t, attrs)
require.Empty(t, attrs)
teardown(t)
}
......@@ -201,7 +201,7 @@ func (cm *CredentialManager) Add(cred *Credential) (err error) {
}
func (cm *CredentialManager) Candidates(disjunction *AttributeDisjunction) []*AttributeIdentifier {
candidates := make([]*AttributeIdentifier, 10)
candidates := make([]*AttributeIdentifier, 0, 10)
for _, attribute := range disjunction.Attributes {
credId := attribute.CredentialTypeIdentifier()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment