diff --git a/spec/vncserver_spec.py b/spec/vncserver_spec.py new file mode 100644 index 0000000..e0f5d28 --- /dev/null +++ b/spec/vncserver_spec.py @@ -0,0 +1,59 @@ +import os +import stat +import tempfile +from mamba import description, context, fcontext, it, fit, before, after +from expects import expect, equal, contain, match + +from helper.spec_helper import start_xvnc, kill_xvnc, run_cmd, clean_env, \ + add_kasmvnc_user_docker, clean_kasm_users, start_xvnc_pexpect, \ + write_config, config_filename + + +def run_vncserver(): + return start_xvnc(f'-config {config_filename}') + + +def temp_file_name(): + return f'/tmp/vncserver.{next(tempfile._get_candidate_names())}' + + +with description('vncserver') as self: + with before.each: + clean_env() + with after.each: + kill_xvnc() + + with context("SSL certs"): + with before.each: + add_kasmvnc_user_docker() + + with it("complains if SSL certs don't exist"): + non_existent_file_name = temp_file_name() + + write_config(f''' + network: + ssl: + pem_certificate: {non_existent_file_name} + ''') + completed_process = run_vncserver() + expect(completed_process.returncode).to(equal(1)) + expect(completed_process.stderr).to( + match(r'certificate file doesn\'t exist')) + + with it("complains if SSL cert not available"): + cert_file_name = temp_file_name() + with open(cert_file_name, 'w') as f: + f.write('test') + os.chmod(cert_file_name, stat.S_IXUSR) + + write_config(f''' + network: + ssl: + pem_certificate: {cert_file_name} + ''') + completed_process = run_vncserver() + expect(completed_process.returncode).to(equal(1)) + expect(completed_process.stderr).to( + match(r'certificate isn\'t readable')) + expect(completed_process.stderr).to( + match(r'addgroup \$USER')) diff --git a/unix/vncserver b/unix/vncserver index 649fbab..96709cc 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -534,79 +534,68 @@ sub CheckRequiredDependenciesArePresent sub CheckSslCertReadable { return if IsDryRun(); - CheckUserHasAccessToSslCertOnDebian(); - CheckUserHasAccessToSslCertOnCentOS(); + RequireSslCertsToBeReadable(); } sub IsDebian { return -f "/etc/debian_version"; } -sub CheckUserHasAccessToSslCertOnDebian { - if (!IsDebian()) { - return; - } - - if (DoesCertKeyRequireSslCertGroup()) { - RequireUserToHaveSslCertGroup(); - } else { - RequireSslCertsToBeReadable(); - } -} - sub RequireSslCertsToBeReadable { my $certFilename = DerivedValue("network.ssl.pem_certificate"); my $certKeyFilename = DerivedValue("network.ssl.pem_key"); - my @unreadableCertFiles = map { -r $_ ? () : $_ } - uniq($certFilename, $certKeyFilename); + @certs = ($certFilename, $certKeyFilename); + @certs = grep defined, @certs; + @certs = uniq @certs; + + my @unreadableCertFiles = map { -r $_ ? () : $_ } @certs; return if (scalar @unreadableCertFiles == 0); - $unreadableCertFiles = join "\n", @unreadableCertFiles; - $logger->warn(<warn(<warn("$certFile: certificate file doesn't exist or isn't a file"); + return; + } + + my $certGroup = FileGroupName $certFile; + my $addUserToGroupCmd = AddUserToGroupCmd $certGroup; + + $logger->warn(</dev/null 2>&1") == 0; } -sub CheckUserHasAccessToSslCertOnCentOS { - if (!IsRpmSystem()) { - return; - } - - if (DoesCertKeyRequireKasmvncCertGroup()) { - RequireUserToHaveKasmvncCertGroup(); - } else { - RequireSslCertsToBeReadable(); - } -} - sub RequireUserToHaveKasmvncCertGroup { my $certGroup = 'kasmvnc-cert'; if (system("groups | grep -qw $certGroup") != 0) { @@ -843,12 +832,12 @@ sub ConfigureDeToRun { } sub AskUserToChooseDeOrManualXstartup { + return if IsDryRun(); + if (PromptingDisabled()) { WarnIfShouldPromptForDe(); return; } - - return if IsDryRun(); return unless shouldPromptUserToSelectDe(); ForgetSelectedDe();