Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Client interface {
WithRelyingPartyUUID(id string) Client
WithCertificateLevel(level string) Client
WithHashType(hashType string) Client
WithNonce(nonce string) Client
WithInteractionType(interactionType string) Client
WithDisplayText60(text string) Client
WithDisplayText200(text string) Client
Expand Down Expand Up @@ -78,6 +79,11 @@ func (c *client) WithHashType(hashType string) Client {
return c
}

func (c *client) WithNonce(nonce string) Client {
c.config.Nonce = nonce
return c
}

func (c *client) WithInteractionType(interactionType string) Client {
c.config.InteractionType = interactionType
return c
Expand Down
14 changes: 14 additions & 0 deletions client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,35 @@ func Test_WithHashType(t *testing.T) {
}
}

func Test_WithNonce(t *testing.T) {
c := NewClient()

tests := []struct {
name string
param string
expected string
}{
{
name: "Success",
param: "1234567890",
expected: "1234567890",
},
{
name: "Empty",
param: "",
expected: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c = c.WithNonce(tt.param)
clientImpl := c.(*client)
assert.Equal(t, tt.expected, clientImpl.config.Nonce)
})
}
}

func Test_WithInteractionType(t *testing.T) {
c := NewClient()

Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Config struct {
RelyingPartyUUID string
CertificateLevel string
HashType string
Nonce string
InteractionType string
DisplayText60 string
DisplayText200 string
Expand Down
1 change: 1 addition & 0 deletions internal/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type AuthenticationRequest struct {
CertificateLevel string `json:"certificateLevel"`
Hash string `json:"hash"`
HashType string `json:"hashType"`
Nonce string `json:"nonce,omitempty"`
AllowedInteractionsOrder []AllowedInteraction `json:"allowedInteractionsOrder"`
}

Expand Down
1 change: 1 addition & 0 deletions internal/requests/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func CreateAuthenticationSession(
CertificateLevel: cfg.CertificateLevel,
Hash: hash,
HashType: cfg.HashType,
Nonce: cfg.Nonce,
AllowedInteractionsOrder: []models.AllowedInteraction{
interaction,
},
Expand Down
13 changes: 13 additions & 0 deletions internal/requests/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func Test_CreateAuthenticationSession_Body(t *testing.T) {
assert.Equal(t, "QUALIFIED", req.CertificateLevel)
assert.Equal(t, "displayTextAndPIN", req.AllowedInteractionsOrder[0].Type)
assert.Equal(t, "Enter PIN1", req.AllowedInteractionsOrder[0].DisplayText60)
assert.Equal(t, "SHA512", req.HashType)
assert.Equal(t, "random-nonce-123", req.Nonce)
assert.Equal(t, identity, req.NationalIdentityNumber)

w.Header().Set("Content-Type", "application/json")
Expand All @@ -52,6 +54,7 @@ func Test_CreateAuthenticationSession_Body(t *testing.T) {
InteractionType: "displayTextAndPIN",
DisplayText60: "Enter PIN1",
HashType: "SHA512",
Nonce: "random-nonce-123",
Timeout: 10 * time.Second,
},
},
Expand All @@ -69,6 +72,8 @@ func Test_CreateAuthenticationSession_Body(t *testing.T) {
assert.Equal(t, "QUALIFIED", req.CertificateLevel)
assert.Equal(t, "verificationCodeChoice", req.AllowedInteractionsOrder[0].Type)
assert.Equal(t, "Enter PIN1", req.AllowedInteractionsOrder[0].DisplayText60)
assert.Equal(t, "SHA512", req.HashType)
assert.Equal(t, "random-nonce-123", req.Nonce)
assert.Equal(t, identity, req.NationalIdentityNumber)

w.Header().Set("Content-Type", "application/json")
Expand All @@ -82,6 +87,7 @@ func Test_CreateAuthenticationSession_Body(t *testing.T) {
InteractionType: "verificationCodeChoice",
DisplayText60: "Enter PIN1",
HashType: "SHA512",
Nonce: "random-nonce-123",
Timeout: 10 * time.Second,
},
},
Expand All @@ -99,6 +105,8 @@ func Test_CreateAuthenticationSession_Body(t *testing.T) {
assert.Equal(t, "QUALIFIED", req.CertificateLevel)
assert.Equal(t, "confirmationMessage", req.AllowedInteractionsOrder[0].Type)
assert.Equal(t, "Confirm the authentication request and enter PIN1", req.AllowedInteractionsOrder[0].DisplayText200)
assert.Equal(t, "SHA512", req.HashType)
assert.Equal(t, "random-nonce-123", req.Nonce)
assert.Equal(t, identity, req.NationalIdentityNumber)

w.Header().Set("Content-Type", "application/json")
Expand All @@ -112,6 +120,7 @@ func Test_CreateAuthenticationSession_Body(t *testing.T) {
InteractionType: "confirmationMessage",
DisplayText200: "Confirm the authentication request and enter PIN1",
HashType: "SHA512",
Nonce: "random-nonce-123",
Timeout: 10 * time.Second,
},
},
Expand All @@ -129,6 +138,8 @@ func Test_CreateAuthenticationSession_Body(t *testing.T) {
assert.Equal(t, "QUALIFIED", req.CertificateLevel)
assert.Equal(t, "confirmationMessageAndVerificationCodeChoice", req.AllowedInteractionsOrder[0].Type)
assert.Equal(t, "Confirm the authentication request and enter PIN1", req.AllowedInteractionsOrder[0].DisplayText200)
assert.Equal(t, "SHA512", req.HashType)
assert.Equal(t, "random-nonce-123", req.Nonce)
assert.Equal(t, identity, req.NationalIdentityNumber)

w.Header().Set("Content-Type", "application/json")
Expand All @@ -142,6 +153,7 @@ func Test_CreateAuthenticationSession_Body(t *testing.T) {
InteractionType: "confirmationMessageAndVerificationCodeChoice",
DisplayText200: "Confirm the authentication request and enter PIN1",
HashType: "SHA512",
Nonce: "random-nonce-123",
Timeout: 10 * time.Second,
},
},
Expand Down Expand Up @@ -170,6 +182,7 @@ func Test_CreateAuthenticationSession(t *testing.T) {
DisplayText60: "Enter PIN1",
DisplayText200: "Confirm the authentication request and enter PIN1",
HashType: "SHA512",
Nonce: "random-nonce-123",
Timeout: 10 * time.Second,
}

Expand Down
Loading