Skip to content
Snippets Groups Projects
Commit e8640855 authored by Lyuben Penkovski's avatar Lyuben Penkovski
Browse files

Merge branch '19-regofuncs-verification-methods' into 'main'

Update regofunc names for retrieving DID verification methods

Closes #19

See merge request gaia-x/data-infrastructure-federation-services/tsa/policy!9
parents dc6de10f 6e2677bd
No related branches found
No related tags found
No related merge requests found
Pipeline #54864 passed with stages
in 3 minutes and 6 seconds
......@@ -16,7 +16,7 @@ include:
- template: 'Workflows/Branch-Pipelines.gitlab-ci.yml'
lint:
image: golangci/golangci-lint:v1.50.0
image: golangci/golangci-lint:v1.50.1
stage: test
tags:
- amd64-docker
......@@ -28,7 +28,7 @@ lint:
- cd /go/src/gitlab.com/${CI_PROJECT_PATH}
unit tests:
image: golang:1.19.2
image: golang:1.19.3
extends: .gotest
stage: test
tags:
......@@ -37,7 +37,7 @@ unit tests:
coverage: '/total:\s+\(statements\)\s+(\d+.\d+\%)/'
govulncheck:
image: golang:1.19.2
image: golang:1.19.3
stage: test
tags:
- amd64-docker
......
......@@ -100,8 +100,8 @@ func main() {
regofunc.Register("didResolve", rego.Function1(didResolverFuncs.ResolveFunc()))
regofunc.Register("taskCreate", rego.Function2(taskFuncs.CreateTaskFunc()))
regofunc.Register("taskListCreate", rego.Function2(taskFuncs.CreateTaskListFunc()))
regofunc.Register("getKey", rego.Function3(signerFuncs.GetKeyFunc()))
regofunc.Register("getAllKeys", rego.Function2(signerFuncs.GetAllKeysFunc()))
regofunc.Register("verificationMethod", rego.Function3(signerFuncs.VerificationMethodFunc()))
regofunc.Register("verificationMethods", rego.Function2(signerFuncs.VerificationMethodsFunc()))
regofunc.Register("addVCProof", rego.Function3(signerFuncs.AddVCProofFunc()))
regofunc.Register("addVPProof", rego.Function4(signerFuncs.AddVPProofFunc()))
regofunc.Register("verifyProof", rego.Function1(signerFuncs.VerifyProofFunc()))
......
FROM golang:1.19.2-alpine3.15 as builder
FROM golang:1.19.3-alpine3.15 as builder
RUN apk add git
......
FROM golang:1.19.2
FROM golang:1.19.3
RUN go install github.com/canthefason/go-watcher/cmd/watcher@v0.2.4
......
......@@ -14,8 +14,10 @@ import (
)
const (
createVCProofPath = "/v1/credential/proof"
createVPProofPath = "/v1/presentation/proof"
verificationMethodPath = "/v1/verification-methods/%s/%s/%s"
verificationMethodsPath = "/v1/verification-methods/%s/%s"
createVCProofPath = "/v1/credential/proof"
createVPProofPath = "/v1/presentation/proof"
)
type SignerFuncs struct {
......@@ -30,9 +32,9 @@ func NewSignerFuncs(signerAddr string, httpClient *http.Client) *SignerFuncs {
}
}
func (sf *SignerFuncs) GetKeyFunc() (*rego.Function, rego.Builtin3) {
func (sf *SignerFuncs) VerificationMethodFunc() (*rego.Function, rego.Builtin3) {
return &rego.Function{
Name: "keys.get",
Name: "verification_method",
Decl: types.NewFunction(types.Args(types.S, types.S, types.S), types.A),
Memoize: true,
},
......@@ -56,7 +58,7 @@ func (sf *SignerFuncs) GetKeyFunc() (*rego.Function, rego.Builtin3) {
return nil, fmt.Errorf("empty keyname")
}
path := fmt.Sprintf("/v1/keys/%s/%s/%s", did, namespace, key)
path := fmt.Sprintf(verificationMethodPath, namespace, key, did)
uri, err := url.ParseRequestURI(sf.signerAddr + path)
if err != nil {
return nil, err
......@@ -86,9 +88,9 @@ func (sf *SignerFuncs) GetKeyFunc() (*rego.Function, rego.Builtin3) {
}
}
func (sf *SignerFuncs) GetAllKeysFunc() (*rego.Function, rego.Builtin2) {
func (sf *SignerFuncs) VerificationMethodsFunc() (*rego.Function, rego.Builtin2) {
return &rego.Function{
Name: "keys.getAll",
Name: "verification_methods",
Decl: types.NewFunction(types.Args(types.S, types.S), types.A),
Memoize: true,
},
......@@ -107,7 +109,7 @@ func (sf *SignerFuncs) GetAllKeysFunc() (*rego.Function, rego.Builtin2) {
return nil, fmt.Errorf("empty key namespace")
}
path := fmt.Sprintf("/v1/keys/%s/%s", did, namespace)
path := fmt.Sprintf(verificationMethodsPath, namespace, did)
uri, err := url.ParseRequestURI(sf.signerAddr + path)
if err != nil {
return nil, err
......
......@@ -14,7 +14,7 @@ import (
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/policy/internal/regofunc"
)
func TestGetKeyFunc(t *testing.T) {
func TestVerificationMethodFunc(t *testing.T) {
expected := `{"key1":"key1 data"}`
signerSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprint(w, expected)
......@@ -23,8 +23,8 @@ func TestGetKeyFunc(t *testing.T) {
keysFuncs := regofunc.NewSignerFuncs(signerSrv.URL, http.DefaultClient)
r := rego.New(
rego.Query(`keys.get("did:web:example.com", "transit", "key1")`),
rego.Function3(keysFuncs.GetKeyFunc()),
rego.Query(`verification_method("did:web:example.com", "transit", "key1")`),
rego.Function3(keysFuncs.VerificationMethodFunc()),
rego.StrictBuiltinErrors(true),
)
resultSet, err := r.Eval(context.Background())
......@@ -35,7 +35,7 @@ func TestGetKeyFunc(t *testing.T) {
assert.Equal(t, expected, string(resultBytes))
}
func TestGetKeyFuncError(t *testing.T) {
func TestVerificationMethodFuncError(t *testing.T) {
signerSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
}))
......@@ -43,19 +43,19 @@ func TestGetKeyFuncError(t *testing.T) {
keysFuncs := regofunc.NewSignerFuncs(signerSrv.URL, http.DefaultClient)
r := rego.New(
rego.Query(`keys.get("did:web:example.com", "transit", "key1")`),
rego.Function3(keysFuncs.GetKeyFunc()),
rego.Query(`verification_method("did:web:example.com", "transit", "key1")`),
rego.Function3(keysFuncs.VerificationMethodFunc()),
rego.StrictBuiltinErrors(true),
)
resultSet, err := r.Eval(context.Background())
assert.Nil(t, resultSet)
assert.Error(t, err)
expectedError := `keys.get("did:web:example.com", "transit", "key1"): eval_builtin_error: keys.get: unexpected response from signer: 404 Not Found`
expectedError := `verification_method("did:web:example.com", "transit", "key1"): eval_builtin_error: verification_method: unexpected response from signer: 404 Not Found`
assert.Equal(t, expectedError, err.Error())
}
func TestGetAllKeysFunc(t *testing.T) {
func TestVerificationMethodsFunc(t *testing.T) {
expected := `[{"key1":"key1 data"},{"key2":"key2 data"}]`
signerSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprint(w, expected)
......@@ -64,8 +64,8 @@ func TestGetAllKeysFunc(t *testing.T) {
keysFuncs := regofunc.NewSignerFuncs(signerSrv.URL, http.DefaultClient)
r := rego.New(
rego.Query(`keys.getAll("did:web:example.com", "transit")`),
rego.Function2(keysFuncs.GetAllKeysFunc()),
rego.Query(`verification_methods("did:web:example.com", "transit")`),
rego.Function2(keysFuncs.VerificationMethodsFunc()),
rego.StrictBuiltinErrors(true),
)
resultSet, err := r.Eval(context.Background())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment