Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aws/amazon-ecs-agent
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f3110aae3b978b7117e9204680e9b27efcf1a935
Choose a base ref
..
head repository: aws/amazon-ecs-agent
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9d1325694410f7e166831f610ad59d0c85caea5e
Choose a head ref
Showing with 31 additions and 4 deletions.
  1. +31 −4 agent/handlers/task_server_setup_test.go
35 changes: 31 additions & 4 deletions agent/handlers/task_server_setup_test.go
Original file line number Diff line number Diff line change
@@ -1052,6 +1052,34 @@ func TestV3ContainerAssociation(t *testing.T) {
assert.Equal(t, expectedAssociationResponse, string(res))
}

func TestTaskHTTPEndpoint301Redirect(t *testing.T) {
testPathsMap := map[string]string{
"http://127.0.0.1/v3///task/": "http://127.0.0.1/v3/task/",
"http://127.0.0.1//v2/credentials/test": "http://127.0.0.1/v2/credentials/test",
}

ctrl := gomock.NewController(t)
defer ctrl.Finish()

state := mock_dockerstate.NewMockTaskEngineState(ctrl)
auditLog := mock_audit.NewMockAuditLogger(ctrl)
statsEngine := mock_stats.NewMockEngine(ctrl)
ecsClient := mock_api.NewMockECSClient(ctrl)

server := taskServerSetup(credentials.NewManager(), auditLog, state, ecsClient, clusterName, statsEngine,
config.DefaultTaskMetadataSteadyStateRate, config.DefaultTaskMetadataBurstRate, "", containerInstanceArn)

for testPath, expectedPath := range testPathsMap {
t.Run(fmt.Sprintf("Test path: %s", testPath), func(t *testing.T) {
recorder := httptest.NewRecorder()
req, _ := http.NewRequest("GET", testPath, nil)
server.Handler.ServeHTTP(recorder, req)
assert.Equal(t, http.StatusMovedPermanently, recorder.Code)
assert.Equal(t, expectedPath, recorder.Header().Get("Location"))
})
}
}

func TestTaskHTTPEndpointErrorCode404(t *testing.T) {
testPaths := []string{
"/",
@@ -1061,7 +1089,6 @@ func TestTaskHTTPEndpointErrorCode404(t *testing.T) {
"/v3/v3-endpoint-id/",
"/v3/v3-endpoint-id/wrong-path",
"/v3/v3-endpoint-id/task/",
"/v3///task/",
"/v3/v3-endpoint-id/task/stats/",
"/v3/v3-endpoint-id/task/stats/wrong-path",
"/v3/v3-endpoint-id/associtions-with-typo/elastic-inference/dev1",
@@ -1101,11 +1128,11 @@ func TestTaskHTTPEndpointErrorCode400(t *testing.T) {
"/v3/wrong-v3-endpoint-id",
"/v3/",
"/v3/wrong-v3-endpoint-id/stats",
"/v3//stats",
"/v3/stats",
"/v3/wrong-v3-endpoint-id/task",
"/v3//task",
"/v3/task",
"/v3/wrong-v3-endpoint-id/task/stats",
"/v3//task/stats",
"/v3/task/stats",
"/v3/wrong-v3-endpoint-id/associations/elastic-inference",
"/v3/wrong-v3-endpoint-id/associations/elastic-inference/dev1",
}