Skip to content

Commit

Permalink
test: add 401 wrong auth test
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Jun 5, 2024
1 parent 0addb57 commit 3486dae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sztp-agent/pkg/secureagent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ type BootstrapServerPostOutput struct {
} `json:"ietf-sztp-bootstrap-server:output"`
}

type BootstrapServerErrorOutput struct {
IetfRestconfErrors struct {
Error []struct {
ErrorType string `json:"error-type"`
ErrorTag string `json:"error-tag"`
ErrorMessage string `json:"error-message"`
} `json:"error"`
} `json:"ietf-restconf:errors"`
}

// Agent is the basic structure to define an agent instance
type Agent struct {
BootstrapURL string // Bootstrap complete URL
Expand Down
24 changes: 24 additions & 0 deletions sztp-agent/pkg/secureagent/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ func TestAgent_doReqBootstrap(t *testing.T) {
ConveyedInformation: "{wrongBASE64}",
},
}
expectedError := BootstrapServerErrorOutput{
IetfRestconfErrors: struct {
Error []struct {
ErrorType string `json:"error-type"`
ErrorTag string `json:"error-tag"`
ErrorMessage string `json:"error-message"`
} `json:"error"`
}{
Error: []struct {
ErrorType string `json:"error-type"`
ErrorTag string `json:"error-tag"`
ErrorMessage string `json:"error-message"`
}{
{
ErrorType: "operation-failed",
ErrorTag: "operation-failed",
ErrorMessage: "failed",
},
},
},
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, pass, _ := r.BasicAuth()
log.Println(user, pass)
Expand All @@ -162,6 +183,9 @@ func TestAgent_doReqBootstrap(t *testing.T) {
case (user + ":" + pass) == "KOBASE64:KO":
w.WriteHeader(200)
output, _ = json.Marshal(expectedFailedBase64)
case (user + ":" + pass) == "KO:KO":
w.WriteHeader(401)
output, _ = json.Marshal(expectedError)
default:
w.WriteHeader(400)
output, _ = json.Marshal(expectedOnboarding)
Expand Down

0 comments on commit 3486dae

Please sign in to comment.