-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added auth v2 request access token api for s2s flow
regenerated APIs using codegen 1.15.0
- Loading branch information
1 parent
f84adae
commit 26cab94
Showing
5 changed files
with
291 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2023 Nuts community | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package iam | ||
|
||
import ( | ||
"github.com/nuts-foundation/nuts-node/vdr/types" | ||
"testing" | ||
|
||
"github.com/nuts-foundation/go-did/did" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWrapper_RequestAccessToken(t *testing.T) { | ||
walletDID := did.MustParseDID("did:test:123") | ||
verifierDID := did.MustParseDID("did:test:456") | ||
body := &RequestAccessTokenJSONRequestBody{Verifier: verifierDID.String()} | ||
|
||
t.Run("ok", func(t *testing.T) { | ||
ctx := newTestClient(t) | ||
ctx.vdr.EXPECT().IsOwner(nil, walletDID).Return(true, nil) | ||
ctx.resolver.EXPECT().Resolve(verifierDID, nil).Return(&did.Document{}, &types.DocumentMetadata{}, nil) | ||
|
||
_, err := ctx.client.RequestAccessToken(nil, RequestAccessTokenRequestObject{Did: walletDID.String(), Body: body}) | ||
|
||
require.NoError(t, err) | ||
}) | ||
t.Run("error - DID not owned", func(t *testing.T) { | ||
ctx := newTestClient(t) | ||
ctx.vdr.EXPECT().IsOwner(nil, walletDID).Return(false, nil) | ||
|
||
_, err := ctx.client.RequestAccessToken(nil, RequestAccessTokenRequestObject{Did: walletDID.String(), Body: body}) | ||
|
||
require.Error(t, err) | ||
assert.ErrorContains(t, err, "not owned by this node") | ||
}) | ||
t.Run("error - invalid DID", func(t *testing.T) { | ||
ctx := newTestClient(t) | ||
|
||
_, err := ctx.client.RequestAccessToken(nil, RequestAccessTokenRequestObject{Did: "invalid", Body: body}) | ||
|
||
require.EqualError(t, err, "did not found: invalid DID") | ||
}) | ||
t.Run("missing request body", func(t *testing.T) { | ||
ctx := newTestClient(t) | ||
|
||
_, err := ctx.client.RequestAccessToken(nil, RequestAccessTokenRequestObject{Did: walletDID.String()}) | ||
|
||
require.Error(t, err) | ||
assert.EqualError(t, err, "missing request body") | ||
}) | ||
t.Run("invalid verifier did", func(t *testing.T) { | ||
ctx := newTestClient(t) | ||
body := &RequestAccessTokenJSONRequestBody{Verifier: "invalid"} | ||
ctx.vdr.EXPECT().IsOwner(nil, walletDID).Return(true, nil) | ||
|
||
_, err := ctx.client.RequestAccessToken(nil, RequestAccessTokenRequestObject{Did: walletDID.String(), Body: body}) | ||
|
||
require.Error(t, err) | ||
assert.EqualError(t, err, "invalid verifier: invalid DID") | ||
}) | ||
t.Run("verifier not found", func(t *testing.T) { | ||
ctx := newTestClient(t) | ||
ctx.vdr.EXPECT().IsOwner(nil, walletDID).Return(true, nil) | ||
ctx.resolver.EXPECT().Resolve(verifierDID, nil).Return(nil, nil, types.ErrNotFound) | ||
|
||
_, err := ctx.client.RequestAccessToken(nil, RequestAccessTokenRequestObject{Did: walletDID.String(), Body: body}) | ||
|
||
require.Error(t, err) | ||
assert.EqualError(t, err, "verifier not found: unable to find the DID document") | ||
}) | ||
} |
Oops, something went wrong.