Commit 5020b49e authored by Sietse Ringers's avatar Sietse Ringers
Browse files

feat: validate that attributes in keyshareserver and myirmaserver configurations exist

parent f7aba437
......@@ -94,6 +94,10 @@ func processConfiguration(conf *Configuration) (*keysharecore.Core, error) {
return nil, server.LogError(err)
}
if conf.IrmaConfiguration.AttributeTypes[conf.KeyshareAttribute] == nil {
return nil, server.LogError(errors.Errorf("Unknown keyshare attribute: %s", conf.KeyshareAttribute))
}
// Setup database
if conf.DB == nil {
switch conf.DBType {
......
......@@ -60,4 +60,9 @@ func TestConfInvalidAESKey(t *testing.T) {
conf.DBType = "undefined"
_, err = New(conf)
assert.Error(t, err)
conf = validConf(t)
conf.KeyshareAttribute = irma.NewAttributeTypeIdentifier("test.test.foo.bar")
_, err = New(conf)
assert.Error(t, err)
}
......@@ -5,6 +5,7 @@ import (
"strings"
"github.com/go-errors/errors"
"github.com/hashicorp/go-multierror"
irma "github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/server"
"github.com/privacybydesign/irmago/server/keyshare"
......@@ -72,6 +73,20 @@ func processConfiguration(conf *Configuration) error {
if len(conf.EmailAttributes) == 0 {
return server.LogError(errors.Errorf("Missing email attributes"))
}
var multierr multierror.Error
for _, attr := range conf.KeyshareAttributes {
if conf.IrmaConfiguration.AttributeTypes[attr] == nil {
multierr.Errors = append(multierr.Errors, errors.Errorf("Unknown keyshare attribute: %s", attr))
}
}
for _, attr := range conf.EmailAttributes {
if conf.IrmaConfiguration.AttributeTypes[attr] == nil {
multierr.Errors = append(multierr.Errors, errors.Errorf("Unknown email attribute: %s", attr))
}
}
if err := multierr.ErrorOrNil(); err != nil {
return server.LogError(err)
}
// Setup email templates
var err error
......
......@@ -47,4 +47,14 @@ func TestConfValidation(t *testing.T) {
conf.DBType = "UNKNOWN"
_, err = New(conf)
assert.Error(t, err)
conf = validConf(t)
conf.KeyshareAttributes = append(conf.KeyshareAttributes, irma.NewAttributeTypeIdentifier("test.test.foo.bar"))
_, err = New(conf)
assert.Error(t, err)
conf = validConf(t)
conf.KeyshareAttributes = append(conf.EmailAttributes, irma.NewAttributeTypeIdentifier("test.test.foo.bar"))
_, err = New(conf)
assert.Error(t, err)
}
Supports Markdown
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