@@ -13,9 +13,10 @@ import (
1313 "sort"
1414 "testing"
1515
16+ mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
17+ "github.com/nginx/agent/v3/internal/model"
1618 "github.com/nginx/agent/v3/test/integration/utils"
1719
18- mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
1920 "github.com/stretchr/testify/suite"
2021)
2122
@@ -26,9 +27,10 @@ const (
2627
2728type ConfigApplyTestSuite struct {
2829 suite.Suite
29- ctx context.Context
30- teardownTest func (testing.TB )
31- nginxInstanceID string
30+ ctx context.Context
31+ teardownTest func (testing.TB )
32+ nginxInstanceID string
33+ mockManagementConfigDir string
3234}
3335
3436type ConfigApplyChunkingTestSuite struct {
@@ -44,6 +46,9 @@ func (s *ConfigApplyTestSuite) SetupSuite() {
4446 s .teardownTest = utils .SetupConnectionTest (s .T (), false , false , false ,
4547 "../../config/agent/nginx-config-with-grpc-client.conf" )
4648 s .nginxInstanceID = utils .VerifyConnection (s .T (), 2 , utils .MockManagementPlaneAPIAddress )
49+
50+ s .mockManagementConfigDir = "/mock-management-plane-grpc/config/" + s .nginxInstanceID
51+
4752 responses := utils .ManagementPlaneResponses (s .T (), 1 , utils .MockManagementPlaneAPIAddress )
4853 s .Require ().Equal (mpi .CommandResponse_COMMAND_STATUS_OK , responses [0 ].GetCommandResponse ().GetStatus ())
4954 s .Require ().Equal ("Successfully updated all files" , responses [0 ].GetCommandResponse ().GetMessage ())
@@ -58,30 +63,67 @@ func (s *ConfigApplyTestSuite) TearDownTest() {
5863 utils .ClearManagementPlaneResponses (s .T (), utils .MockManagementPlaneAPIAddress )
5964}
6065
66+ // Config Apply with no changes to config
6167func (s * ConfigApplyTestSuite ) TestConfigApply_Test1_TestNoConfigChanges () {
6268 slog .Info ("starting config apply no config changes test" )
6369 utils .PerformConfigApply (s .T (), s .nginxInstanceID , utils .MockManagementPlaneAPIAddress )
6470 responses := utils .ManagementPlaneResponses (s .T (), 2 , utils .MockManagementPlaneAPIAddress )
6571 s .T ().Logf ("Config apply responses: %v" , responses )
6672
73+ manifestFiles := map [string ]* model.ManifestFile {
74+ "/etc/nginx/mime.types" : {
75+ ManifestFileMeta : & model.ManifestFileMeta {
76+ Name : "/etc/nginx/mime.types" ,
77+ Hash : "b5XR19dePAcpB9hFYipp0jEQ0SZsFv8SKzEJuLIfOuk=" ,
78+ Size : 5349 ,
79+ Referenced : true ,
80+ },
81+ },
82+ "/etc/nginx/nginx.conf" : {
83+ ManifestFileMeta : & model.ManifestFileMeta {
84+ Name : "/etc/nginx/nginx.conf" ,
85+ Hash : "gJ1slpIAUmHAiSo5ZIalKvE40b1hJCgaXasQOMab6kc=" ,
86+ Size : 1172 ,
87+ Referenced : true ,
88+ },
89+ },
90+ }
91+
92+ if os .Getenv ("IMAGE_PATH" ) == "/nginx-plus/agent" {
93+ manifestFiles ["/etc/nginx/nginx.conf" ].ManifestFileMeta .Hash = "/SWXYYenb2EcJNg6fiuzlkdj91nBdsMdF1vLm7Wybvc="
94+ manifestFiles ["/etc/nginx/nginx.conf" ].ManifestFileMeta .Size = 1218
95+ }
96+
97+ utils .CheckManifestFile (s .T (), utils .Container , manifestFiles )
98+
6799 s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , responses [0 ].GetCommandResponse ().GetStatus ())
68100 s .Equal ("Successfully updated all files" , responses [0 ].GetCommandResponse ().GetMessage ())
69101 s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , responses [1 ].GetCommandResponse ().GetStatus ())
70102 s .Equal ("Config apply successful, no files to change" , responses [1 ].GetCommandResponse ().GetMessage ())
71103 slog .Info ("finished config apply no config changes test" )
72104}
73105
106+ // Config apply - Add, Update and Delete Referenced file from Management Plane
74107func (s * ConfigApplyTestSuite ) TestConfigApply_Test2_TestValidConfig () {
75108 slog .Info ("starting config apply valid config test" )
76- newConfigFile := "../../config/nginx/nginx-with-test-location.conf"
109+ // Update nginx.conf
110+ utils .WriteConfigFileMock (s .T (), s .nginxInstanceID , "/etc/nginx/test/test.conf" ,
111+ "/etc/nginx/test/test.conf" , "/etc/nginx/test/test.conf" )
112+
113+ // Delete mime.types
114+ code , _ , removeErr := utils .MockManagementPlaneGrpcContainer .Exec (context .Background (), []string {
115+ "rm" ,
116+ s .mockManagementConfigDir + "/etc/nginx/mime.types" ,
117+ })
77118
78- if os .Getenv ("IMAGE_PATH" ) == "/nginx-plus/agent" {
79- newConfigFile = "../../config/nginx/nginx-plus-with-test-location.conf"
80- }
119+ s .Require ().NoError (removeErr )
120+ s .Equal (0 , code )
121+
122+ // Add test.conf
81123 err := utils .MockManagementPlaneGrpcContainer .CopyFileToContainer (
82124 s .ctx ,
83- newConfigFile ,
84- fmt . Sprintf ( "/mock-management-plane-grpc/config/%s/ etc/nginx/nginx .conf", s . nginxInstanceID ) ,
125+ "configs/test.conf" ,
126+ s . mockManagementConfigDir + "/ etc/nginx/test/test .conf" ,
85127 0o666 ,
86128 )
87129 s .Require ().NoError (err )
@@ -90,6 +132,27 @@ func (s *ConfigApplyTestSuite) TestConfigApply_Test2_TestValidConfig() {
90132 responses := utils .ManagementPlaneResponses (s .T (), 2 , utils .MockManagementPlaneAPIAddress )
91133 s .T ().Logf ("Config apply responses: %v" , responses )
92134
135+ manifestFiles := map [string ]* model.ManifestFile {
136+ "/etc/nginx/test/test.conf" : {
137+ ManifestFileMeta : & model.ManifestFileMeta {
138+ Name : "/etc/nginx/test/test.conf" ,
139+ Hash : "BF1ztX59kP/N81XcIv3JlPp82j7gzTsVIk2RGxdAta8=" ,
140+ Size : 175 ,
141+ Referenced : true ,
142+ },
143+ },
144+ "/etc/nginx/nginx.conf" : {
145+ ManifestFileMeta : & model.ManifestFileMeta {
146+ Name : "/etc/nginx/nginx.conf" ,
147+ Hash : "/SsQwpZTdJVRa1+bex7OdZoogvVT0tnTOwwO59vpsoM=" ,
148+ Size : 1360 ,
149+ Referenced : true ,
150+ },
151+ },
152+ }
153+
154+ utils .CheckManifestFile (s .T (), utils .Container , manifestFiles )
155+
93156 sort .Slice (responses , func (i , j int ) bool {
94157 return responses [i ].GetCommandResponse ().GetMessage () < responses [j ].GetCommandResponse ().GetMessage ()
95158 })
@@ -101,7 +164,60 @@ func (s *ConfigApplyTestSuite) TestConfigApply_Test2_TestValidConfig() {
101164 slog .Info ("finished config apply valid config test" )
102165}
103166
104- func (s * ConfigApplyTestSuite ) TestConfigApply_Test3_TestInvalidConfig () {
167+ // Add, Update and Delete file on DataPlane - Trigger update file overview
168+ func (s * ConfigApplyTestSuite ) TestConfigApply_Test3_DataPlaneUpdate () {
169+ slog .Info ("starting config apply data plane update test" )
170+ // Add test2.conf to dataplane
171+ err := utils .Container .CopyFileToContainer (
172+ s .ctx ,
173+ "configs/test2.conf" ,
174+ "/etc/nginx/test/test2.conf" ,
175+ 0o666 ,
176+ )
177+ s .Require ().NoError (err )
178+
179+ // Delete test.conf from dataplane
180+ code , _ , removeErr := utils .Container .Exec (context .Background (), []string {
181+ "rm" ,
182+ "/etc/nginx/test/test.conf" ,
183+ })
184+
185+ s .Require ().NoError (removeErr )
186+ s .Equal (0 , code )
187+
188+ // Update nginx.conf to reference new file
189+ utils .WriteConfigFileDataplane (s .T (), "/etc/nginx/test/test2.conf" ,
190+ "/etc/nginx/test/test2.conf" , "/etc/nginx/test/test2.conf" )
191+
192+ manifestFiles := map [string ]* model.ManifestFile {
193+ "/etc/nginx/test/test2.conf" : {
194+ ManifestFileMeta : & model.ManifestFileMeta {
195+ Name : "/etc/nginx/test/test2.conf" ,
196+ Hash : "mV4nVTx8BObqxSwcJprkJesiCJH+oTO89RgZxFuFEJo=" ,
197+ Size : 136 ,
198+ Referenced : true ,
199+ },
200+ },
201+ "/etc/nginx/nginx.conf" : {
202+ ManifestFileMeta : & model.ManifestFileMeta {
203+ Name : "/etc/nginx/nginx.conf" ,
204+ Hash : "q8Zf3Cv5UOAVyfigx5Mr4mwJpLIxApN1H0UzYKKTAiU=" ,
205+ Size : 1363 ,
206+ Referenced : true ,
207+ },
208+ },
209+ }
210+
211+ responses := utils .ManagementPlaneResponses (s .T (), 1 , utils .MockManagementPlaneAPIAddress )
212+
213+ utils .CheckManifestFile (s .T (), utils .Container , manifestFiles )
214+
215+ s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , responses [0 ].GetCommandResponse ().GetStatus ())
216+ s .Equal ("Successfully updated all files" , responses [0 ].GetCommandResponse ().GetMessage ())
217+ slog .Info ("finished config apply data plane update test" )
218+ }
219+
220+ func (s * ConfigApplyTestSuite ) TestConfigApply_Test4_TestInvalidConfig () {
105221 slog .Info ("starting config apply invalid config test" )
106222 err := utils .MockManagementPlaneGrpcContainer .CopyFileToContainer (
107223 s .ctx ,
@@ -116,6 +232,27 @@ func (s *ConfigApplyTestSuite) TestConfigApply_Test3_TestInvalidConfig() {
116232 responses := utils .ManagementPlaneResponses (s .T (), 2 , utils .MockManagementPlaneAPIAddress )
117233 s .T ().Logf ("Config apply responses: %v" , responses )
118234
235+ manifestFiles := map [string ]* model.ManifestFile {
236+ "/etc/nginx/test/test2.conf" : {
237+ ManifestFileMeta : & model.ManifestFileMeta {
238+ Name : "/etc/nginx/test/test2.conf" ,
239+ Hash : "mV4nVTx8BObqxSwcJprkJesiCJH+oTO89RgZxFuFEJo=" ,
240+ Size : 136 ,
241+ Referenced : true ,
242+ },
243+ },
244+ "/etc/nginx/nginx.conf" : {
245+ ManifestFileMeta : & model.ManifestFileMeta {
246+ Name : "/etc/nginx/nginx.conf" ,
247+ Hash : "q8Zf3Cv5UOAVyfigx5Mr4mwJpLIxApN1H0UzYKKTAiU=" ,
248+ Size : 1363 ,
249+ Referenced : true ,
250+ },
251+ },
252+ }
253+
254+ utils .CheckManifestFile (s .T (), utils .Container , manifestFiles )
255+
119256 s .Equal (mpi .CommandResponse_COMMAND_STATUS_ERROR , responses [0 ].GetCommandResponse ().GetStatus ())
120257 s .Equal ("Config apply failed, rolling back config" , responses [0 ].GetCommandResponse ().GetMessage ())
121258 s .Equal (configApplyErrorMessage , responses [0 ].GetCommandResponse ().GetError ())
@@ -125,13 +262,33 @@ func (s *ConfigApplyTestSuite) TestConfigApply_Test3_TestInvalidConfig() {
125262 slog .Info ("finished config apply invalid config test" )
126263}
127264
128- func (s * ConfigApplyTestSuite ) TestConfigApply_Test4_TestFileNotInAllowedDirectory () {
265+ func (s * ConfigApplyTestSuite ) TestConfigApply_Test5_TestFileNotInAllowedDirectory () {
129266 slog .Info ("starting config apply file not in allowed directory test" )
130267 utils .PerformInvalidConfigApply (s .T (), s .nginxInstanceID )
131268
132269 responses := utils .ManagementPlaneResponses (s .T (), 1 , utils .MockManagementPlaneAPIAddress )
133270 s .T ().Logf ("Config apply responses: %v" , responses )
134271
272+ manifestFiles := map [string ]* model.ManifestFile {
273+ "/etc/nginx/test/test2.conf" : {
274+ ManifestFileMeta : & model.ManifestFileMeta {
275+ Name : "/etc/nginx/test/test2.conf" ,
276+ Hash : "mV4nVTx8BObqxSwcJprkJesiCJH+oTO89RgZxFuFEJo=" ,
277+ Size : 136 ,
278+ Referenced : true ,
279+ },
280+ },
281+ "/etc/nginx/nginx.conf" : {
282+ ManifestFileMeta : & model.ManifestFileMeta {
283+ Name : "/etc/nginx/nginx.conf" ,
284+ Hash : "q8Zf3Cv5UOAVyfigx5Mr4mwJpLIxApN1H0UzYKKTAiU=" ,
285+ Size : 1363 ,
286+ Referenced : true ,
287+ },
288+ },
289+ }
290+ utils .CheckManifestFile (s .T (), utils .Container , manifestFiles )
291+
135292 s .Equal (mpi .CommandResponse_COMMAND_STATUS_FAILURE , responses [0 ].GetCommandResponse ().GetStatus ())
136293 s .Equal ("Config apply failed" , responses [0 ].GetCommandResponse ().GetMessage ())
137294 s .Equal (
@@ -179,6 +336,27 @@ func (s *ConfigApplyChunkingTestSuite) TestConfigApplyChunking() {
179336 return responses [i ].GetCommandResponse ().GetMessage () < responses [j ].GetCommandResponse ().GetMessage ()
180337 })
181338
339+ manifestFiles := map [string ]* model.ManifestFile {
340+ "/etc/nginx/mime.types" : {
341+ ManifestFileMeta : & model.ManifestFileMeta {
342+ Name : "/etc/nginx/mime.types" ,
343+ Hash : "b5XR19dePAcpB9hFYipp0jEQ0SZsFv8SKzEJuLIfOuk=" ,
344+ Size : 5349 ,
345+ Referenced : true ,
346+ },
347+ },
348+ "/etc/nginx/nginx.conf" : {
349+ ManifestFileMeta : & model.ManifestFileMeta {
350+ Name : "/etc/nginx/nginx.conf" ,
351+ Hash : "dfDpjGOjOhWWhX43y/d+zBulXCisx+BVYj2eEEud6ac=" ,
352+ Size : 886910 ,
353+ Referenced : true ,
354+ },
355+ },
356+ }
357+
358+ utils .CheckManifestFile (s .T (), utils .Container , manifestFiles )
359+
182360 s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , responses [0 ].GetCommandResponse ().GetStatus ())
183361 s .Equal ("Config apply successful" , responses [0 ].GetCommandResponse ().GetMessage ())
184362 s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , responses [1 ].GetCommandResponse ().GetStatus ())
0 commit comments