@@ -31,8 +31,8 @@ import (
3131)
3232
3333const (
34- // configApplyErrorMessage = "failed to parse config invalid " +
35- // "number of arguments in \"worker_processes\" directive in /etc/nginx/nginx.conf:1"
34+ configApplyErrorMessage = "failed to parse config invalid " +
35+ "number of arguments in \" worker_processes\" directive in /etc/nginx/nginx.conf:1"
3636
3737 retryCount = 5
3838 retryWaitTime = 4 * time .Second
@@ -200,15 +200,15 @@ func TestGrpc_ConfigApply(t *testing.T) {
200200 assert .Equal (t , mpi .CommandResponse_COMMAND_STATUS_OK , responses [0 ].GetCommandResponse ().GetStatus ())
201201 assert .Equal (t , "Successfully updated all files" , responses [0 ].GetCommandResponse ().GetMessage ())
202202
203- // t.Run("Test 1: No config changes", func(t *testing.T) {
204- // clearManagementPlaneResponses(t)
205- // performConfigApply(t, nginxInstanceID)
206- // responses = getManagementPlaneResponses(t, 1)
207- // t.Logf("Config apply responses: %v", responses)
208- //
209- // assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
210- // assert.Equal(t, "Config apply successful, no files to change", responses[0].GetCommandResponse().GetMessage())
211- // })
203+ t .Run ("Test 1: No config changes" , func (t * testing.T ) {
204+ clearManagementPlaneResponses (t )
205+ performConfigApply (t , nginxInstanceID )
206+ responses = getManagementPlaneResponses (t , 1 )
207+ t .Logf ("Config apply responses: %v" , responses )
208+
209+ assert .Equal (t , mpi .CommandResponse_COMMAND_STATUS_OK , responses [0 ].GetCommandResponse ().GetStatus ())
210+ assert .Equal (t , "Config apply successful, no files to change" , responses [0 ].GetCommandResponse ().GetMessage ())
211+ })
212212
213213 t .Run ("Test 2: Valid config" , func (t * testing.T ) {
214214 clearManagementPlaneResponses (t )
@@ -235,44 +235,44 @@ func TestGrpc_ConfigApply(t *testing.T) {
235235 assert .Equal (t , "Successfully updated all files" , responses [1 ].GetCommandResponse ().GetMessage ())
236236 })
237237
238- // t.Run("Test 3: Invalid config", func(t *testing.T) {
239- // clearManagementPlaneResponses(t)
240- // err := mockManagementPlaneGrpcContainer.CopyFileToContainer(
241- // ctx,
242- // "../config/nginx/invalid-nginx.conf",
243- // fmt.Sprintf("/mock-management-plane-grpc/config/%s/etc/nginx/nginx.conf", nginxInstanceID),
244- // 0o666,
245- // )
246- // require.NoError(t, err)
247- //
248- // performConfigApply(t, nginxInstanceID)
249- //
250- // responses = getManagementPlaneResponses(t, 2)
251- // t.Logf("Config apply responses: %v", responses)
252- //
253- // assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_ERROR, responses[0].GetCommandResponse().GetStatus())
254- // assert.Equal(t, "Config apply failed, rolling back config", responses[0].GetCommandResponse().GetMessage())
255- // assert.Equal(t, configApplyErrorMessage, responses[0].GetCommandResponse().GetError())
256- // assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_FAILURE, responses[1].GetCommandResponse().GetStatus())
257- // assert.Equal(t, "Config apply failed, rollback successful", responses[1].GetCommandResponse().GetMessage())
258- // assert.Equal(t, configApplyErrorMessage, responses[1].GetCommandResponse().GetError())
259- // })
260- //
261- // t.Run("Test 4: File not in allowed directory", func(t *testing.T) {
262- // clearManagementPlaneResponses(t)
263- // performInvalidConfigApply(t, nginxInstanceID)
264- //
265- // responses = getManagementPlaneResponses(t, 1)
266- // t.Logf("Config apply responses: %v", responses)
267- //
268- // assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_FAILURE, responses[0].GetCommandResponse().GetStatus())
269- // assert.Equal(t, "Config apply failed", responses[0].GetCommandResponse().GetMessage())
270- // assert.Equal(
271- // t,
272- // "file not in allowed directories /unknown/nginx.conf",
273- // responses[0].GetCommandResponse().GetError(),
274- // )
275- // })
238+ t .Run ("Test 3: Invalid config" , func (t * testing.T ) {
239+ clearManagementPlaneResponses (t )
240+ err := mockManagementPlaneGrpcContainer .CopyFileToContainer (
241+ ctx ,
242+ "../config/nginx/invalid-nginx.conf" ,
243+ fmt .Sprintf ("/mock-management-plane-grpc/config/%s/etc/nginx/nginx.conf" , nginxInstanceID ),
244+ 0o666 ,
245+ )
246+ require .NoError (t , err )
247+
248+ performConfigApply (t , nginxInstanceID )
249+
250+ responses = getManagementPlaneResponses (t , 2 )
251+ t .Logf ("Config apply responses: %v" , responses )
252+
253+ assert .Equal (t , mpi .CommandResponse_COMMAND_STATUS_ERROR , responses [0 ].GetCommandResponse ().GetStatus ())
254+ assert .Equal (t , "Config apply failed, rolling back config" , responses [0 ].GetCommandResponse ().GetMessage ())
255+ assert .Equal (t , configApplyErrorMessage , responses [0 ].GetCommandResponse ().GetError ())
256+ assert .Equal (t , mpi .CommandResponse_COMMAND_STATUS_FAILURE , responses [1 ].GetCommandResponse ().GetStatus ())
257+ assert .Equal (t , "Config apply failed, rollback successful" , responses [1 ].GetCommandResponse ().GetMessage ())
258+ assert .Equal (t , configApplyErrorMessage , responses [1 ].GetCommandResponse ().GetError ())
259+ })
260+
261+ t .Run ("Test 4: File not in allowed directory" , func (t * testing.T ) {
262+ clearManagementPlaneResponses (t )
263+ performInvalidConfigApply (t , nginxInstanceID )
264+
265+ responses = getManagementPlaneResponses (t , 1 )
266+ t .Logf ("Config apply responses: %v" , responses )
267+
268+ assert .Equal (t , mpi .CommandResponse_COMMAND_STATUS_FAILURE , responses [0 ].GetCommandResponse ().GetStatus ())
269+ assert .Equal (t , "Config apply failed" , responses [0 ].GetCommandResponse ().GetMessage ())
270+ assert .Equal (
271+ t ,
272+ "file not in allowed directories /unknown/nginx.conf" ,
273+ responses [0 ].GetCommandResponse ().GetError (),
274+ )
275+ })
276276}
277277
278278func performConfigApply (t * testing.T , nginxInstanceID string ) {
@@ -288,52 +288,52 @@ func performConfigApply(t *testing.T, nginxInstanceID string) {
288288 assert .Equal (t , http .StatusOK , resp .StatusCode ())
289289}
290290
291- // func performInvalidConfigApply(t *testing.T, nginxInstanceID string) {
292- // t.Helper()
293- //
294- // client := resty.New()
295- // client.SetRetryCount(retryCount).SetRetryWaitTime(retryWaitTime).SetRetryMaxWaitTime(retryMaxWaitTime)
296- //
297- // body := fmt.Sprintf(`{
298- // "message_meta": {
299- // "message_id": "e2254df9-8edd-4900-91ce-88782473bcb9",
300- // "correlation_id": "9673f3b4-bf33-4d98-ade1-ded9266f6818",
301- // "timestamp": "2023-01-15T01:30:15.01Z"
302- // },
303- // "config_apply_request": {
304- // "overview": {
305- // "files": [{
306- // "file_meta": {
307- // "name": "/etc/nginx/nginx.conf",
308- // "hash": "ea57e443-e968-3a50-b842-f37112acde71",
309- // "modifiedTime": "2023-01-15T01:30:15.01Z",
310- // "permissions": "0644",
311- // "size": 0
312- // },
313- // "action": "FILE_ACTION_UPDATE"
314- // },
315- // {
316- // "file_meta": {
317- // "name": "/unknown/nginx.conf",
318- // "hash": "bd1f337d-6874-35ea-9d4d-2b543efd42cf",
319- // "modifiedTime": "2023-01-15T01:30:15.01Z",
320- // "permissions": "0644",
321- // "size": 0
322- // },
323- // "action": "FILE_ACTION_ADD"
324- // }],
325- // "config_version": {
326- // "instance_id": "%s",
327- // "version": "6f343257-55e3-309e-a2eb-bb13af5f80f4"
328- // }
329- // }
330- // }
331- // }`, nginxInstanceID)
332- // url := fmt.Sprintf("http://%s/api/v1/requests", mockManagementPlaneAPIAddress)
333- // resp, err := client.R().EnableTrace().SetBody(body).Post(url)
334- // require.NoError(t, err)
335- // assert.Equal(t, http.StatusOK, resp.StatusCode())
336- // }
291+ func performInvalidConfigApply (t * testing.T , nginxInstanceID string ) {
292+ t .Helper ()
293+
294+ client := resty .New ()
295+ client .SetRetryCount (retryCount ).SetRetryWaitTime (retryWaitTime ).SetRetryMaxWaitTime (retryMaxWaitTime )
296+
297+ body := fmt .Sprintf (`{
298+ "message_meta": {
299+ "message_id": "e2254df9-8edd-4900-91ce-88782473bcb9",
300+ "correlation_id": "9673f3b4-bf33-4d98-ade1-ded9266f6818",
301+ "timestamp": "2023-01-15T01:30:15.01Z"
302+ },
303+ "config_apply_request": {
304+ "overview": {
305+ "files": [{
306+ "file_meta": {
307+ "name": "/etc/nginx/nginx.conf",
308+ "hash": "ea57e443-e968-3a50-b842-f37112acde71",
309+ "modifiedTime": "2023-01-15T01:30:15.01Z",
310+ "permissions": "0644",
311+ "size": 0
312+ },
313+ "action": "FILE_ACTION_UPDATE"
314+ },
315+ {
316+ "file_meta": {
317+ "name": "/unknown/nginx.conf",
318+ "hash": "bd1f337d-6874-35ea-9d4d-2b543efd42cf",
319+ "modifiedTime": "2023-01-15T01:30:15.01Z",
320+ "permissions": "0644",
321+ "size": 0
322+ },
323+ "action": "FILE_ACTION_ADD"
324+ }],
325+ "config_version": {
326+ "instance_id": "%s",
327+ "version": "6f343257-55e3-309e-a2eb-bb13af5f80f4"
328+ }
329+ }
330+ }
331+ }` , nginxInstanceID )
332+ url := fmt .Sprintf ("http://%s/api/v1/requests" , mockManagementPlaneAPIAddress )
333+ resp , err := client .R ().EnableTrace ().SetBody (body ).Post (url )
334+ require .NoError (t , err )
335+ assert .Equal (t , http .StatusOK , resp .StatusCode ())
336+ }
337337
338338func getManagementPlaneResponses (t * testing.T , numberOfExpectedResponses int ) []* mpi.DataPlaneResponse {
339339 t .Helper ()
0 commit comments