@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add test coverage for SSH key revocation

Summary: Depends on D18928. Ref T13043. Add some automated test coverage for SSH revocation rules.

Test Plan: Ran tests, got a clean bill of health.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13043

Differential Revision: https://secure.phabricator.com/D18929

+80
+2
src/__phutil_library_map__.php
··· 2133 2133 'PhabricatorAuthSSHKeyRevokeController' => 'applications/auth/controller/PhabricatorAuthSSHKeyRevokeController.php', 2134 2134 'PhabricatorAuthSSHKeySearchEngine' => 'applications/auth/query/PhabricatorAuthSSHKeySearchEngine.php', 2135 2135 'PhabricatorAuthSSHKeyTableView' => 'applications/auth/view/PhabricatorAuthSSHKeyTableView.php', 2136 + 'PhabricatorAuthSSHKeyTestCase' => 'applications/auth/__tests__/PhabricatorAuthSSHKeyTestCase.php', 2136 2137 'PhabricatorAuthSSHKeyTransaction' => 'applications/auth/storage/PhabricatorAuthSSHKeyTransaction.php', 2137 2138 'PhabricatorAuthSSHKeyTransactionQuery' => 'applications/auth/query/PhabricatorAuthSSHKeyTransactionQuery.php', 2138 2139 'PhabricatorAuthSSHKeyViewController' => 'applications/auth/controller/PhabricatorAuthSSHKeyViewController.php', ··· 7441 7442 'PhabricatorAuthSSHKeyRevokeController' => 'PhabricatorAuthSSHKeyController', 7442 7443 'PhabricatorAuthSSHKeySearchEngine' => 'PhabricatorApplicationSearchEngine', 7443 7444 'PhabricatorAuthSSHKeyTableView' => 'AphrontView', 7445 + 'PhabricatorAuthSSHKeyTestCase' => 'PhabricatorTestCase', 7444 7446 'PhabricatorAuthSSHKeyTransaction' => 'PhabricatorApplicationTransaction', 7445 7447 'PhabricatorAuthSSHKeyTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 7446 7448 'PhabricatorAuthSSHKeyViewController' => 'PhabricatorAuthSSHKeyController',
+78
src/applications/auth/__tests__/PhabricatorAuthSSHKeyTestCase.php
··· 1 + <?php 2 + 3 + final class PhabricatorAuthSSHKeyTestCase extends PhabricatorTestCase { 4 + 5 + protected function getPhabricatorTestCaseConfiguration() { 6 + return array( 7 + self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true, 8 + ); 9 + } 10 + 11 + public function testRevokeSSHKey() { 12 + $user = $this->generateNewTestUser(); 13 + $raw_key = 'ssh-rsa hunter2'; 14 + 15 + $ssh_key = PhabricatorAuthSSHKey::initializeNewSSHKey($user, $user); 16 + 17 + // Add the key to the user's account. 18 + $xactions = array(); 19 + $xactions[] = $ssh_key->getApplicationTransactionTemplate() 20 + ->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_NAME) 21 + ->setNewValue('key1'); 22 + $xactions[] = $ssh_key->getApplicationTransactionTemplate() 23 + ->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_KEY) 24 + ->setNewValue($raw_key); 25 + $this->applyTransactions($user, $ssh_key, $xactions); 26 + 27 + $ssh_key->reload(); 28 + $this->assertTrue((bool)$ssh_key->getIsActive()); 29 + 30 + // Revoke it. 31 + $xactions = array(); 32 + $xactions[] = $ssh_key->getApplicationTransactionTemplate() 33 + ->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_DEACTIVATE) 34 + ->setNewValue(true); 35 + $this->applyTransactions($user, $ssh_key, $xactions); 36 + 37 + $ssh_key->reload(); 38 + $this->assertFalse((bool)$ssh_key->getIsActive()); 39 + 40 + // Try to add the revoked key back. This should fail with a validation 41 + // error because the key was previously revoked by the user. 42 + $revoked_key = PhabricatorAuthSSHKey::initializeNewSSHKey($user, $user); 43 + $xactions = array(); 44 + $xactions[] = $ssh_key->getApplicationTransactionTemplate() 45 + ->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_NAME) 46 + ->setNewValue('key2'); 47 + $xactions[] = $ssh_key->getApplicationTransactionTemplate() 48 + ->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_KEY) 49 + ->setNewValue($raw_key); 50 + 51 + $caught = null; 52 + try { 53 + $this->applyTransactions($user, $ssh_key, $xactions); 54 + } catch (PhabricatorApplicationTransactionValidationException $ex) { 55 + $errors = $ex->getErrors(); 56 + $this->assertEqual(1, count($errors)); 57 + $caught = head($errors)->getType(); 58 + } 59 + 60 + $this->assertEqual(PhabricatorAuthSSHKeyTransaction::TYPE_KEY, $caught); 61 + } 62 + 63 + private function applyTransactions( 64 + PhabricatorUser $actor, 65 + PhabricatorAuthSSHKey $key, 66 + array $xactions) { 67 + 68 + $content_source = $this->newContentSource(); 69 + 70 + $editor = $key->getApplicationTransactionEditor() 71 + ->setActor($actor) 72 + ->setContinueOnNoEffect(true) 73 + ->setContinueOnMissingFields(true) 74 + ->setContentSource($content_source) 75 + ->applyTransactions($key, $xactions); 76 + } 77 + 78 + }