Verified Commit e2b985ae authored by Jess's avatar Jess
Browse files

Issue #3340142 by mstrelan, quietone, xjm: Convert testJail() to use expectException

parent e6a220a7
Loading
Loading
Loading
Loading
Loading
+4 −20
Original line number Diff line number Diff line
@@ -91,26 +91,10 @@ public function _writeDirectory($base, $files = []): void {
   */
  public function testJail(): void {
    $source = $this->_buildFakeModule();

    // This convoluted piece of code is here because our testing framework does
    // not support expecting exceptions.
    $got_it = FALSE;
    try {
      $this->testConnection->copyDirectory($source, sys_get_temp_dir());
    }
    catch (FileTransferException) {
      $got_it = TRUE;
    }
    $this->assertTrue($got_it, 'Was not able to copy a directory outside of the jailed area.');

    $got_it = TRUE;
    try {
    $this->testConnection->copyDirectory($source, $this->root . '/' . PublicStream::basePath());
    }
    catch (FileTransferException) {
      $got_it = FALSE;
    }
    $this->assertTrue($got_it, 'Was able to copy a directory inside of the jailed area');
    $this->expectException(FileTransferException::class);
    $this->expectExceptionMessage('@directory is outside of the @jail');
    $this->testConnection->copyDirectory($source, sys_get_temp_dir());
  }

}