Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13993203
D18929.id45398.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D18929.id45398.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2133,6 +2133,7 @@
'PhabricatorAuthSSHKeyRevokeController' => 'applications/auth/controller/PhabricatorAuthSSHKeyRevokeController.php',
'PhabricatorAuthSSHKeySearchEngine' => 'applications/auth/query/PhabricatorAuthSSHKeySearchEngine.php',
'PhabricatorAuthSSHKeyTableView' => 'applications/auth/view/PhabricatorAuthSSHKeyTableView.php',
+ 'PhabricatorAuthSSHKeyTestCase' => 'applications/auth/__tests__/PhabricatorAuthSSHKeyTestCase.php',
'PhabricatorAuthSSHKeyTransaction' => 'applications/auth/storage/PhabricatorAuthSSHKeyTransaction.php',
'PhabricatorAuthSSHKeyTransactionQuery' => 'applications/auth/query/PhabricatorAuthSSHKeyTransactionQuery.php',
'PhabricatorAuthSSHKeyViewController' => 'applications/auth/controller/PhabricatorAuthSSHKeyViewController.php',
@@ -7441,6 +7442,7 @@
'PhabricatorAuthSSHKeyRevokeController' => 'PhabricatorAuthSSHKeyController',
'PhabricatorAuthSSHKeySearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorAuthSSHKeyTableView' => 'AphrontView',
+ 'PhabricatorAuthSSHKeyTestCase' => 'PhabricatorTestCase',
'PhabricatorAuthSSHKeyTransaction' => 'PhabricatorApplicationTransaction',
'PhabricatorAuthSSHKeyTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhabricatorAuthSSHKeyViewController' => 'PhabricatorAuthSSHKeyController',
diff --git a/src/applications/auth/__tests__/PhabricatorAuthSSHKeyTestCase.php b/src/applications/auth/__tests__/PhabricatorAuthSSHKeyTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/applications/auth/__tests__/PhabricatorAuthSSHKeyTestCase.php
@@ -0,0 +1,78 @@
+<?php
+
+final class PhabricatorAuthSSHKeyTestCase extends PhabricatorTestCase {
+
+ protected function getPhabricatorTestCaseConfiguration() {
+ return array(
+ self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
+ );
+ }
+
+ public function testRevokeSSHKey() {
+ $user = $this->generateNewTestUser();
+ $raw_key = 'ssh-rsa hunter2';
+
+ $ssh_key = PhabricatorAuthSSHKey::initializeNewSSHKey($user, $user);
+
+ // Add the key to the first user's account.
+ $xactions = array();
+ $xactions[] = $ssh_key->getApplicationTransactionTemplate()
+ ->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_NAME)
+ ->setNewValue('key1');
+ $xactions[] = $ssh_key->getApplicationTransactionTemplate()
+ ->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_KEY)
+ ->setNewValue($raw_key);
+ $this->applyTransactions($user, $ssh_key, $xactions);
+
+ $ssh_key->reload();
+ $this->assertTrue((bool)$ssh_key->getIsActive());
+
+ // Deactivate it.
+ $xactions = array();
+ $xactions[] = $ssh_key->getApplicationTransactionTemplate()
+ ->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_DEACTIVATE)
+ ->setNewValue(true);
+ $this->applyTransactions($user, $ssh_key, $xactions);
+
+ $ssh_key->reload();
+ $this->assertFalse((bool)$ssh_key->getIsActive());
+
+ // Try to add the revoked key back. This should fail with a validation
+ // error because the key was previously revoked by the user.
+ $revoked_key = PhabricatorAuthSSHKey::initializeNewSSHKey($user, $user);
+ $xactions = array();
+ $xactions[] = $ssh_key->getApplicationTransactionTemplate()
+ ->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_NAME)
+ ->setNewValue('key2');
+ $xactions[] = $ssh_key->getApplicationTransactionTemplate()
+ ->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_KEY)
+ ->setNewValue($raw_key);
+
+ $caught = null;
+ try {
+ $this->applyTransactions($user, $ssh_key, $xactions);
+ } catch (PhabricatorApplicationTransactionValidationException $ex) {
+ $errors = $ex->getErrors();
+ $this->assertEqual(1, count($errors));
+ $caught = head($errors)->getType();
+ }
+
+ $this->assertEqual(PhabricatorAuthSSHKeyTransaction::TYPE_KEY, $caught);
+ }
+
+ private function applyTransactions(
+ PhabricatorUser $actor,
+ PhabricatorAuthSSHKey $key,
+ array $xactions) {
+
+ $content_source = $this->newContentSource();
+
+ $editor = $key->getApplicationTransactionEditor()
+ ->setActor($actor)
+ ->setContinueOnNoEffect(true)
+ ->setContinueOnMissingFields(true)
+ ->setContentSource($content_source)
+ ->applyTransactions($key, $xactions);
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Oct 23, 9:21 PM (3 w, 22 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6745152
Default Alt Text
D18929.id45398.diff (4 KB)
Attached To
Mode
D18929: Add test coverage for SSH key revocation
Attached
Detach File
Event Timeline
Log In to Comment