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

return a 404 if not found instead of redirect to ui #6658

Merged
merged 3 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 8 additions & 4 deletions api/allocations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"context"
"fmt"
"os"
"reflect"
"sort"
Expand Down Expand Up @@ -265,8 +266,10 @@ func TestAllocations_ExecErrors(t *testing.T) {
}
job.Canonicalize()

allocID := uuid.Generate()

alloc := &Allocation{
ID: "",
ID: allocID,
Namespace: DefaultNamespace,
EvalID: uuid.Generate(),
Name: "foo-bar[1]",
Expand All @@ -280,9 +283,10 @@ func TestAllocations_ExecErrors(t *testing.T) {

// make a request that will result in an error
// ensure the error is what we expect
_, err := a.Exec(context.Background(), alloc, "bar", false, []string{"command"}, os.Stdin, os.Stdout, os.Stderr, sizeCh, nil)
require.Contains(t, err.Error(), "Unexpected response code: 301")
require.Contains(t, err.Error(), "Moved Permanently")
exitCode, err := a.Exec(context.Background(), alloc, "bar", false, []string{"command"}, os.Stdin, os.Stdout, os.Stderr, sizeCh, nil)

require.Equal(t, exitCode, -2)
require.Equal(t, err.Error(), fmt.Sprintf("Unknown allocation \"%s\"", allocID))
}

func TestAllocations_ShouldMigrate(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions command/agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ func handleUI(h http.Handler) http.Handler {

func handleRootRedirect() http.Handler {
drewbailey marked this conversation as resolved.
Show resolved Hide resolved
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/" {
DingoEatingFuzz marked this conversation as resolved.
Show resolved Hide resolved
w.WriteHeader(http.StatusNotFound)
return
}

http.Redirect(w, req, "/ui/", 307)
return
drewbailey marked this conversation as resolved.
Show resolved Hide resolved
})
Expand Down