1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-08 04:20:07 +02:00

Parse nginx files + tests

This commit is contained in:
2022-03-14 23:35:08 +01:00
parent 26badc759e
commit a0e7aec228
7 changed files with 260 additions and 5 deletions

View File

@ -66,6 +66,9 @@
C42759672627662800093CAE /* NSMenuExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42759662627662800093CAE /* NSMenuExtension.swift */; }; C42759672627662800093CAE /* NSMenuExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42759662627662800093CAE /* NSMenuExtension.swift */; };
C42759682627662800093CAE /* NSMenuExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42759662627662800093CAE /* NSMenuExtension.swift */; }; C42759682627662800093CAE /* NSMenuExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42759662627662800093CAE /* NSMenuExtension.swift */; };
C42C49DB27C2806F0074ABAC /* MainMenu+FixMyValet.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42C49DA27C2806F0074ABAC /* MainMenu+FixMyValet.swift */; }; C42C49DB27C2806F0074ABAC /* MainMenu+FixMyValet.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42C49DA27C2806F0074ABAC /* MainMenu+FixMyValet.swift */; };
C42CFB1627DFDE7900862737 /* nicoverbruggen.test in Resources */ = {isa = PBXBuildFile; fileRef = C42CFB1527DFDE7900862737 /* nicoverbruggen.test */; };
C42CFB1827DFDFDC00862737 /* nicoverbruggen_isolated.test in Resources */ = {isa = PBXBuildFile; fileRef = C42CFB1727DFDFDC00862737 /* nicoverbruggen_isolated.test */; };
C42CFB1A27DFE8BD00862737 /* NginxParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42CFB1927DFE8BD00862737 /* NginxParserTest.swift */; };
C43603A0275E67610028EFC6 /* AppDelegate+Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */; }; C43603A0275E67610028EFC6 /* AppDelegate+Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */; };
C43603A1275E67610028EFC6 /* AppDelegate+Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */; }; C43603A1275E67610028EFC6 /* AppDelegate+Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */; };
C43A8A1A25D9CD1000591B77 /* Utility.swift in Sources */ = {isa = PBXBuildFile; fileRef = C43A8A1925D9CD1000591B77 /* Utility.swift */; }; C43A8A1A25D9CD1000591B77 /* Utility.swift in Sources */ = {isa = PBXBuildFile; fileRef = C43A8A1925D9CD1000591B77 /* Utility.swift */; };
@ -254,6 +257,9 @@
C4232EE42612526500158FC6 /* Credits.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = Credits.html; sourceTree = "<group>"; }; C4232EE42612526500158FC6 /* Credits.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = Credits.html; sourceTree = "<group>"; };
C42759662627662800093CAE /* NSMenuExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSMenuExtension.swift; sourceTree = "<group>"; }; C42759662627662800093CAE /* NSMenuExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSMenuExtension.swift; sourceTree = "<group>"; };
C42C49DA27C2806F0074ABAC /* MainMenu+FixMyValet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MainMenu+FixMyValet.swift"; sourceTree = "<group>"; }; C42C49DA27C2806F0074ABAC /* MainMenu+FixMyValet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MainMenu+FixMyValet.swift"; sourceTree = "<group>"; };
C42CFB1527DFDE7900862737 /* nicoverbruggen.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = nicoverbruggen.test; sourceTree = "<group>"; };
C42CFB1727DFDFDC00862737 /* nicoverbruggen_isolated.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = nicoverbruggen_isolated.test; sourceTree = "<group>"; };
C42CFB1927DFE8BD00862737 /* NginxParserTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NginxParserTest.swift; sourceTree = "<group>"; };
C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+Notifications.swift"; sourceTree = "<group>"; }; C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+Notifications.swift"; sourceTree = "<group>"; };
C43A8A1925D9CD1000591B77 /* Utility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utility.swift; sourceTree = "<group>"; }; C43A8A1925D9CD1000591B77 /* Utility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utility.swift; sourceTree = "<group>"; };
C43A8A1F25D9D1D700591B77 /* brew.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = brew.json; sourceTree = "<group>"; }; C43A8A1F25D9D1D700591B77 /* brew.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = brew.json; sourceTree = "<group>"; };
@ -417,6 +423,8 @@
C40C7F1C27720E1400DDDCDC /* Test Files */ = { C40C7F1C27720E1400DDDCDC /* Test Files */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C42CFB1527DFDE7900862737 /* nicoverbruggen.test */,
C42CFB1727DFDFDC00862737 /* nicoverbruggen_isolated.test */,
C4AF9F70275445FF00D44ED0 /* valet-config.json */, C4AF9F70275445FF00D44ED0 /* valet-config.json */,
C43A8A1F25D9D1D700591B77 /* brew.json */, C43A8A1F25D9D1D700591B77 /* brew.json */,
C4F30B06278E195800755FCE /* brew-services.json */, C4F30B06278E195800755FCE /* brew-services.json */,
@ -639,6 +647,7 @@
C4AF9F76275447F100D44ED0 /* ValetConfigParserTest.swift */, C4AF9F76275447F100D44ED0 /* ValetConfigParserTest.swift */,
C4F780AD25D80B37000DBC97 /* ExtensionParserTest.swift */, C4F780AD25D80B37000DBC97 /* ExtensionParserTest.swift */,
C43A8A2325D9D20D00591B77 /* BrewJsonParserTest.swift */, C43A8A2325D9D20D00591B77 /* BrewJsonParserTest.swift */,
C42CFB1927DFE8BD00862737 /* NginxParserTest.swift */,
); );
path = Parsers; path = Parsers;
sourceTree = "<group>"; sourceTree = "<group>";
@ -863,12 +872,14 @@
files = ( files = (
54FCFD27276C883F004CE748 /* SelectPreferenceView.xib in Resources */, 54FCFD27276C883F004CE748 /* SelectPreferenceView.xib in Resources */,
54FCFD2E276C8D67004CE748 /* HotkeyPreferenceView.xib in Resources */, 54FCFD2E276C8D67004CE748 /* HotkeyPreferenceView.xib in Resources */,
C42CFB1827DFDFDC00862737 /* nicoverbruggen_isolated.test in Resources */,
C4F780A825D80AE8000DBC97 /* php.ini in Resources */, C4F780A825D80AE8000DBC97 /* php.ini in Resources */,
C4068CA527B0780A00544CD5 /* CheckboxPreferenceView.xib in Resources */, C4068CA527B0780A00544CD5 /* CheckboxPreferenceView.xib in Resources */,
C43A8A2025D9D1D700591B77 /* brew.json in Resources */, C43A8A2025D9D1D700591B77 /* brew.json in Resources */,
C4AF9F72275445FF00D44ED0 /* valet-config.json in Resources */, C4AF9F72275445FF00D44ED0 /* valet-config.json in Resources */,
C44C1992276E44CB0072762D /* ProgressWindow.storyboard in Resources */, C44C1992276E44CB0072762D /* ProgressWindow.storyboard in Resources */,
C4F30B08278E195800755FCE /* brew-services.json in Resources */, C4F30B08278E195800755FCE /* brew-services.json in Resources */,
C42CFB1627DFDE7900862737 /* nicoverbruggen.test in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -1031,6 +1042,7 @@
C44C198E276E3A1C0072762D /* ProgressWindow.swift in Sources */, C44C198E276E3A1C0072762D /* ProgressWindow.swift in Sources */,
C415938027A1B54F00D2E1B7 /* PhpFrameworks.swift in Sources */, C415938027A1B54F00D2E1B7 /* PhpFrameworks.swift in Sources */,
C4D9ADC9277611A0007277F4 /* InternalSwitcher.swift in Sources */, C4D9ADC9277611A0007277F4 /* InternalSwitcher.swift in Sources */,
C42CFB1A27DFE8BD00862737 /* NginxParserTest.swift in Sources */,
C4F30B0B278E203C00755FCE /* MainMenu+Startup.swift in Sources */, C4F30B0B278E203C00755FCE /* MainMenu+Startup.swift in Sources */,
C40B24F227A310770018C7D2 /* Events.swift in Sources */, C40B24F227A310770018C7D2 /* Events.swift in Sources */,
C4F30B0A278E1A1A00755FCE /* ComposerJson.swift in Sources */, C4F30B0A278E1A1A00755FCE /* ComposerJson.swift in Sources */,

View File

@ -0,0 +1,26 @@
//
// NginxParserTest.swift
// phpmon-tests
//
// Created by Nico Verbruggen on 29/11/2021.
// Copyright © 2021 Nico Verbruggen. All rights reserved.
//
import XCTest
class NginxParserTest: XCTestCase {
static var regularUrl: URL {
return Bundle(for: Self.self).url(forResource: "nicoverbruggen", withExtension: "test")!
}
static var isolatedUrl: URL {
return Bundle(for: Self.self).url(forResource: "nicoverbruggen_isolated", withExtension: "test")!
}
func testCanDetermineIsolation() throws {
XCTAssertNil(ValetSite.isolatedVersion(NginxParserTest.regularUrl.path))
XCTAssertEqual("8.1", ValetSite.isolatedVersion(NginxParserTest.isolatedUrl.path))
}
}

View File

@ -0,0 +1,93 @@
server {
listen 127.0.0.1:80;
#listen 127.0.0.1:80; # valet loopback
server_name nicoverbruggen.test www.nicoverbruggen.test *.nicoverbruggen.test;
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 nicoverbruggen.test www.nicoverbruggen.test *.nicoverbruggen.test;
root /;
charset utf-8;
client_max_body_size 512M;
http2_push_preload on;
location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
internal;
alias /;
try_files $uri $uri/;
}
ssl_certificate "/Users/nicoverbruggen/.config/valet/Certificates/nicoverbruggen.test.crt";
ssl_certificate_key "/Users/nicoverbruggen/.config/valet/Certificates/nicoverbruggen.test.key";
location / {
rewrite ^ "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php" last;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log "/Users/nicoverbruggen/.config/valet/Log/nginx-error.log";
error_page 404 "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php";
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass "unix:/Users/nicoverbruggen/.config/valet/valet.sock";
fastcgi_index "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php";
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php";
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 127.0.0.1:60;
#listen 127.0.0.1:60; # valet loopback
server_name nicoverbruggen.test www.nicoverbruggen.test *.nicoverbruggen.test;
root /;
charset utf-8;
client_max_body_size 128M;
add_header X-Robots-Tag 'noindex, nofollow, nosnippet, noarchive';
location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
internal;
alias /;
try_files $uri $uri/;
}
location / {
rewrite ^ "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php" last;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log "/Users/nicoverbruggen/.config/valet/Log/nginx-error.log";
error_page 404 "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php";
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass "unix:/Users/nicoverbruggen/.config/valet/valet.sock";
fastcgi_index "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php";
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php";
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
}

View File

@ -0,0 +1,94 @@
server {
listen 127.0.0.1:80;
#listen 127.0.0.1:80; # valet loopback
server_name nicoverbruggen.test www.nicoverbruggen.test *.nicoverbruggen.test;
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 nicoverbruggen.test www.nicoverbruggen.test *.nicoverbruggen.test;
root /;
charset utf-8;
client_max_body_size 512M;
http2_push_preload on;
location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
internal;
alias /;
try_files $uri $uri/;
}
ssl_certificate "/Users/nicoverbruggen/.config/valet/Certificates/nicoverbruggen.test.crt";
ssl_certificate_key "/Users/nicoverbruggen/.config/valet/Certificates/nicoverbruggen.test.key";
location / {
rewrite ^ "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php" last;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log "/Users/nicoverbruggen/.config/valet/Log/nginx-error.log";
error_page 404 "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php";
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# ISOLATED_PHP_VERSION=php@8.1
fastcgi_pass "unix:/Users/nicoverbruggen/.config/valet/valet81.sock";
fastcgi_index "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php";
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php";
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 127.0.0.1:60;
#listen 127.0.0.1:60; # valet loopback
server_name nicoverbruggen.test www.nicoverbruggen.test *.nicoverbruggen.test;
root /;
charset utf-8;
client_max_body_size 128M;
add_header X-Robots-Tag 'noindex, nofollow, nosnippet, noarchive';
location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
internal;
alias /;
try_files $uri $uri/;
}
location / {
rewrite ^ "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php" last;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log "/Users/nicoverbruggen/.config/valet/Log/nginx-error.log";
error_page 404 "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php";
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass "unix:/Users/nicoverbruggen/.config/valet/valet.sock";
fastcgi_index "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php";
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME "/Users/nicoverbruggen/.composer/vendor/laravel/valet/server.php";
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
}

View File

@ -24,6 +24,6 @@ class PhpVersionDetectionTest: XCTestCase {
"php@5.4" // should be omitted, not supported "php@5.4" // should be omitted, not supported
], checkBinaries: false) ], checkBinaries: false)
XCTAssertEqual(outcome, ["8.0", "7.0", "5.6"]) XCTAssertEqual(outcome, ["8.0", "7.0"])
} }
} }

View File

@ -12,7 +12,7 @@ class ValetVersionExtractorTest: XCTestCase {
func testDetermineValetVersion() { func testDetermineValetVersion() {
let version = valet("--version", sudo: false) let version = valet("--version", sudo: false)
XCTAssert(version.contains("Laravel Valet 2.")) XCTAssert(version.contains("Laravel Valet"))
} }
} }

View File

@ -83,11 +83,16 @@ class ValetSite {
determineDriver() determineDriver()
} }
/**
Determine whether a site is isolated.
*/
public func determineIsolated() { public func determineIsolated() {
// TODO: (ISOLATION) Determine whether the domain is isolated by checking for `# Valet isolated PHP version` if let version = ValetSite.isolatedVersion("~/.config/valet/Nginx/\(self.name).\(self.tld)") {
// This needs to be checked in: "~/.config/valet/Nginx/\(self.name).\(self.tld)" self.isolatedPhpVersion = PhpEnv.shared.cachedPhpInstallations[version]
} else {
self.isolatedPhpVersion = nil self.isolatedPhpVersion = nil
} }
}
/** /**
Checks if a certificate file can be found in the `valet/Certificates` directory. Checks if a certificate file can be found in the `valet/Certificates` directory.
@ -195,4 +200,29 @@ class ValetSite {
Log.err("Something went wrong parsing the .valetphprc file") Log.err("Something went wrong parsing the .valetphprc file")
} }
} }
// MARK: File Parsing
public static func isolatedVersion(_ file: String) -> String? {
if Filesystem.fileExists(file) && grepContains(file: file, query: "# ISOLATED_PHP_VERSION=") {
let regex = try! NSRegularExpression(
pattern: #"(ISOLATED_PHP_VERSION=(php@)?)((?<major>\d)(.)?(?<minor>\d))"#,
options: []
)
let fileContents = try! String(contentsOfFile: file)
let match = regex.firstMatch(in: fileContents, range: NSMakeRange(0, fileContents.count))
let majorRange = Range(match!.range(withName: "major"), in: fileContents)!
let minorRange = Range(match!.range(withName: "minor"), in: fileContents)!
let major: String = fileContents[majorRange]
let minor: String = fileContents[minorRange]
return "\(major).\(minor)"
}
return nil
}
} }