Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add 401 wrong auth test #330

Merged
merged 1 commit into from
Jun 5, 2024
Merged
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
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: "protocol",
ErrorTag: "access-denied",
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
Loading