Skip to content

Commit b2d192f

Browse files
committed
fix tests
1 parent 5e3f0a5 commit b2d192f

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

internal/watcher/instance/nginx_config_parser_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ func TestNginxConfigParser_Parse(t *testing.T) {
336336
{
337337
name: "Test 3: File outside allowed directories",
338338
instance: protos.GetNginxPlusInstance([]string{}),
339-
content: testconfig.GetNginxConfigWithNotAllowedDir(allowedFile.Name(), notAllowedFile.Name()),
339+
content: testconfig.GetNginxConfigWithNotAllowedDir(errorLog.Name(), allowedFile.Name(),
340+
notAllowedFile.Name(), accessLog.Name()),
340341
expectedConfigContext: &model.NginxConfigContext{
341342
StubStatus: &model.APIDetails{},
342343
PlusAPI: &model.APIDetails{},
@@ -348,19 +349,19 @@ func TestNginxConfigParser_Parse(t *testing.T) {
348349
},
349350
AccessLogs: []*model.AccessLog{
350351
{
351-
Name: "/var/log/nginx/access.log",
352+
Name: accessLog.Name(),
352353
Format: "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent " +
353354
"\"$http_referer\" \"$http_user_agent\" \"$http_x_forwarded_for\" \"$bytes_sent\" " +
354355
"\"$request_length\" \"$request_time\" \"$gzip_ratio\" $server_protocol ",
355-
Permissions: "",
356-
Readable: false,
356+
Permissions: "0600",
357+
Readable: true,
357358
},
358359
},
359360
ErrorLogs: []*model.ErrorLog{
360361
{
361-
Name: "/var/log/nginx/error.log",
362-
Permissions: "",
363-
Readable: false,
362+
Name: errorLog.Name(),
363+
Permissions: "0600",
364+
Readable: true,
364365
},
365366
},
366367
NAPSysLogServers: nil,

test/config/nginx/nginx-not-allowed-dir.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
worker_processes 1;
2-
error_log /var/log/nginx/error.log;
2+
error_log %s;
33
events {
44
worker_connections 1024;
55
}
@@ -15,7 +15,7 @@ http {
1515
'"$bytes_sent" "$request_length" "$request_time" '
1616
'"$gzip_ratio" $server_protocol ';
1717

18-
access_log /var/log/nginx/access.log main;
18+
access_log %s main;
1919

2020
sendfile on;
2121
keepalive_timeout 65;

test/config/nginx_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ func GetNginxConfigWithMultipleAccessLogs(
3131
)
3232
}
3333

34-
func GetNginxConfigWithNotAllowedDir(notAllowedFileDir, fileDir string) string {
35-
return fmt.Sprintf(embedNginxConfWithNotAllowedDir, notAllowedFileDir, fileDir)
34+
func GetNginxConfigWithNotAllowedDir(errorLogFile, notAllowedFile, allowedFileDir, accessLogFile string) string {
35+
return fmt.Sprintf(embedNginxConfWithNotAllowedDir, errorLogFile, notAllowedFile, allowedFileDir, accessLogFile)
3636
}

0 commit comments

Comments
 (0)