Skip to content

Commit

Permalink
fix(LH-69113): Use queueTriggerState instead of state when updating A…
Browse files Browse the repository at this point in the history
…SA credentials (#27)

* fix(LH-69113): Use queueTriggerState instead of state when updating ASA credentials

Using state to trigger a state machine can cause errors if there's already a state machine running. We should be using queueTriggerState instead.

* test(LH-69113): Fix broken tests
  • Loading branch information
siddhuwarrier authored Aug 30, 2023
1 parent cba1be0 commit 2512bf0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions client/device/asa/asaconfig/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package asaconfig
import (
"context"
"encoding/json"
"strings"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/crypto"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model"
"strings"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
Expand Down Expand Up @@ -129,7 +130,7 @@ func makeUpdateCredentialsReqBody(isWaitForUserToUpdateCreds bool, creds []byte)
}
} else {
return &updateCredentialsBodyWithState{
State: "WAIT_FOR_USER_TO_UPDATE_CREDS",
QueueTriggerState: "WAIT_FOR_USER_TO_UPDATE_CREDS",
SmContext: SmContext{
Credentials: string(creds),
},
Expand All @@ -143,8 +144,8 @@ type updateBody struct {
}

type updateCredentialsBodyWithState struct {
State string `json:"state"`
SmContext SmContext `json:"stateMachineContext"`
QueueTriggerState string `json:"queueTriggerState"`
SmContext SmContext `json:"stateMachineContext"`
}

type updateCredentialsBody struct {
Expand Down
11 changes: 6 additions & 5 deletions client/device/asa/asaconfig/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"crypto/rand"
"crypto/rsa"
"fmt"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/crypto"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
"time"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/crypto"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model"
"github.com/stretchr/testify/assert"

internalHttp "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/jsonutil"
"github.com/jarcoal/httpmock"
Expand Down Expand Up @@ -205,7 +206,7 @@ func TestAsaConfigUpdateCredentials(t *testing.T) {
assert.Nil(t, err)

expectedBody := updateCredentialsBodyWithState{
State: "WAIT_FOR_USER_TO_UPDATE_CREDS",
QueueTriggerState: "WAIT_FOR_USER_TO_UPDATE_CREDS",
SmContext: SmContext{
Credentials: fmt.Sprintf(`{"username":"%s","password":"%s"}`, input.Username, input.Password),
},
Expand Down Expand Up @@ -246,7 +247,7 @@ func TestAsaConfigUpdateCredentials(t *testing.T) {
assert.Nil(t, err)

expectedState := "WAIT_FOR_USER_TO_UPDATE_CREDS"
assert.Equal(t, requestBody.State, expectedState)
assert.Equal(t, requestBody.QueueTriggerState, expectedState)

credentials, err := jsonutil.UnmarshalStruct[model.Credentials]([]byte(requestBody.SmContext.Credentials))
assert.Nil(t, err)
Expand Down

0 comments on commit 2512bf0

Please sign in to comment.