Commit 3a09637f authored by Sietse Ringers's avatar Sietse Ringers
Browse files

fix: bug that would randomize the order of candidate attribute sets

parent 7c92972b
package irmaclient
import (
"encoding/json"
"errors"
"os"
......@@ -10,6 +11,7 @@ import (
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/fs"
"github.com/privacybydesign/irmago/internal/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
......@@ -152,6 +154,32 @@ func TestCandidates(t *testing.T) {
require.Empty(t, attrs)
}
func TestCandidateConjunctionOrder(t *testing.T) {
client := parseStorage(t)
j := `[
[
[
"irma-demo.RU.studentCard.level",
"test.test.mijnirma.email"
]
]
]`
cdc := irma.AttributeConDisCon{}
require.NoError(t, json.Unmarshal([]byte(j), &cdc))
assert.Equal(t,
"irma-demo.RU.studentCard.level",
cdc[0][0][0].Type.String(),
)
for i := 1; i < 20; i++ {
candidates, missing := client.CheckSatisfiability(cdc)
require.Empty(t, missing)
require.Equal(t, "irma-demo.RU.studentCard.level", candidates[0][0][0].Type.String())
}
}
func TestCredentialRemoval(t *testing.T) {
client := parseStorage(t)
defer test.ClearTestStorage(t)
......
......@@ -193,13 +193,14 @@ func (b *BaseRequest) GetNonce(*atum.Timestamp) *big.Int {
// CredentialTypes returns an array of all credential types occuring in this conjunction.
func (c AttributeCon) CredentialTypes() []CredentialTypeIdentifier {
var result []CredentialTypeIdentifier
tmp := map[CredentialTypeIdentifier]struct{}{}
for _, attr := range c {
tmp[attr.Type.CredentialTypeIdentifier()] = struct{}{}
}
for cred := range tmp {
result = append(result, cred)
typ := attr.Type.CredentialTypeIdentifier()
if len(result) == 0 || result[len(result)-1] != typ {
result = append(result, typ)
}
}
return result
}
......
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