From 884784d024545986e85b7cc562051adcd7e8a017 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 10 May 2022 10:26:48 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Handle=20trailing=20semicolon=20?= =?UTF-8?q?(#170)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP Monitor.xcodeproj/project.pbxproj | 10 +++- .../Parsers/NginxConfigurationTest.swift | 14 +++++ .../nginx/nginx-secure-proxy-custom-tld.test | 57 +++++++++++++++++++ .../Nginx/NginxConfiguration.swift | 2 +- 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 phpmon-tests/Test Files/nginx/nginx-secure-proxy-custom-tld.test diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 1e68707..8fb9e2a 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 5420395926135DC100FB00FA /* PrefsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395826135DC100FB00FA /* PrefsVC.swift */; }; 5420395F2613607600FB00FA /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395E2613607600FB00FA /* Preferences.swift */; }; + 54A18D40282A566E000A0D81 /* nginx-secure-proxy-custom-tld.test in Resources */ = {isa = PBXBuildFile; fileRef = 54A18D3F282A566E000A0D81 /* nginx-secure-proxy-custom-tld.test */; }; 54B48B5F275F66AE006D90C5 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B48B5E275F66AE006D90C5 /* Application.swift */; }; 54B48B60275F66AE006D90C5 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B48B5E275F66AE006D90C5 /* Application.swift */; }; 54D9E0B227E4F51E003B9AD9 /* HotKeysController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54D9E0AC27E4F51E003B9AD9 /* HotKeysController.swift */; }; @@ -272,6 +273,7 @@ /* Begin PBXFileReference section */ 5420395826135DC100FB00FA /* PrefsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefsVC.swift; sourceTree = ""; }; 5420395E2613607600FB00FA /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = ""; }; + 54A18D3F282A566E000A0D81 /* nginx-secure-proxy-custom-tld.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "nginx-secure-proxy-custom-tld.test"; sourceTree = ""; }; 54B48B5E275F66AE006D90C5 /* Application.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Application.swift; sourceTree = ""; }; 54D9E0AC27E4F51E003B9AD9 /* HotKeysController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HotKeysController.swift; sourceTree = ""; }; 54D9E0AD27E4F51E003B9AD9 /* Key.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Key.swift; sourceTree = ""; }; @@ -657,8 +659,9 @@ C459B4BE27F6093A00E9B4B4 /* nginx */ = { isa = PBXGroup; children = ( - C42F26752805FEE200938AC7 /* nginx-secure-proxy.test */, C459B4BC27F6093700E9B4B4 /* nginx-proxy.test */, + C42F26752805FEE200938AC7 /* nginx-secure-proxy.test */, + 54A18D3F282A566E000A0D81 /* nginx-secure-proxy-custom-tld.test */, C42CFB1527DFDE7900862737 /* nginx-site.test */, C42CFB1727DFDFDC00862737 /* nginx-site-isolated.test */, ); @@ -1093,6 +1096,7 @@ C44C1992276E44CB0072762D /* ProgressWindow.storyboard in Resources */, C42F26762805FEE200938AC7 /* nginx-secure-proxy.test in Resources */, C4F30B08278E195800755FCE /* brew-services.json in Resources */, + 54A18D40282A566E000A0D81 /* nginx-secure-proxy-custom-tld.test in Resources */, C42CFB1627DFDE7900862737 /* nginx-site.test in Resources */, C459B4BD27F6093700E9B4B4 /* nginx-proxy.test in Resources */, ); @@ -1506,7 +1510,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 780; + CURRENT_PROJECT_VERSION = 781; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; @@ -1532,7 +1536,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 780; + CURRENT_PROJECT_VERSION = 781; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; diff --git a/phpmon-tests/Parsers/NginxConfigurationTest.swift b/phpmon-tests/Parsers/NginxConfigurationTest.swift index c4f3d50..a189e50 100644 --- a/phpmon-tests/Parsers/NginxConfigurationTest.swift +++ b/phpmon-tests/Parsers/NginxConfigurationTest.swift @@ -10,6 +10,8 @@ import XCTest class NginxConfigurationTest: XCTestCase { + // MARK: - Test Files + static var regularUrl: URL { return Bundle(for: Self.self).url(forResource: "nginx-site", withExtension: "test")! } @@ -26,6 +28,12 @@ class NginxConfigurationTest: XCTestCase { return Bundle(for: Self.self).url(forResource: "nginx-secure-proxy", withExtension: "test")! } + static var customTldProxyUrl: URL { + return Bundle(for: Self.self).url(forResource: "nginx-secure-proxy-custom-tld", withExtension: "test")! + } + + // MARK: - Tests + func testCanDetermineSiteNameAndTld() throws { XCTAssertEqual( "nginx-site", @@ -64,4 +72,10 @@ class NginxConfigurationTest: XCTestCase { XCTAssertEqual("http://127.0.0.1:90", proxied.proxy) } + func testCanDetermineProxyWithCustomTld() throws { + let proxied = NginxConfiguration(filePath: NginxConfigurationTest.customTldProxyUrl.path) + XCTAssertTrue(proxied.contents.contains("# valet stub: secure.proxy.valet.conf")) + XCTAssertEqual("http://localhost:8080", proxied.proxy) + } + } diff --git a/phpmon-tests/Test Files/nginx/nginx-secure-proxy-custom-tld.test b/phpmon-tests/Test Files/nginx/nginx-secure-proxy-custom-tld.test new file mode 100644 index 0000000..6dbe50b --- /dev/null +++ b/phpmon-tests/Test Files/nginx/nginx-secure-proxy-custom-tld.test @@ -0,0 +1,57 @@ +# valet stub: secure.proxy.valet.conf + +server { + listen 127.0.0.1:80; + #listen 127.0.0.1:80; # valet loopback + server_name live.whatagraph.dev.com www.live.whatagraph.dev.com *.live.whatagraph.dev.com; + return 301 https://$host$request_uri; +} + +server { + listen 127.0.0.1:443 ssl http2; + #listen 127.0.0.1:443 ssl http2; # valet loopback + server_name live.whatagraph.dev.com www.live.whatagraph.dev.com *.live.whatagraph.dev.com; + root /; + charset utf-8; + client_max_body_size 128M; + http2_push_preload on; + + location /41c270e4-5535-4daa-b23e-c269744c2f45/ { + internal; + alias /; + try_files $uri $uri/; + } + + ssl_certificate "/Users/phpmon/.config/valet/Certificates/live.whatagraph.dev.com.crt"; + ssl_certificate_key "/Users/phpmon/.config/valet/Certificates/live.whatagraph.dev.com.key"; + + access_log off; + error_log "/Users/phpmon/.config/valet/Log/live.whatagraph.dev.com-error.log"; + + error_page 404 "/Users/phpmon/.composer/vendor/laravel/valet/server.php"; + + location / { + proxy_pass http://localhost:8080/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Client-Verify SUCCESS; + proxy_set_header X-Client-DN $ssl_client_s_dn; + proxy_set_header X-SSL-Subject $ssl_client_s_dn; + proxy_set_header X-SSL-Issuer $ssl_client_i_dn; + proxy_set_header X-NginX-Proxy true; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_http_version 1.1; + proxy_read_timeout 1800; + proxy_connect_timeout 1800; + chunked_transfer_encoding on; + proxy_redirect off; + proxy_buffering off; + } + + location ~ /\.ht { + deny all; + } +} diff --git a/phpmon/Domain/Integrations/Nginx/NginxConfiguration.swift b/phpmon/Domain/Integrations/Nginx/NginxConfiguration.swift index ada62fe..a02b723 100644 --- a/phpmon/Domain/Integrations/Nginx/NginxConfiguration.swift +++ b/phpmon/Domain/Integrations/Nginx/NginxConfiguration.swift @@ -40,7 +40,7 @@ class NginxConfiguration { */ lazy var proxy: String? = { let regex = try! NSRegularExpression( - pattern: #"proxy_pass (?.*:\d*);"#, + pattern: #"proxy_pass (?.*:\d*)(\/*);"#, options: [] )