Skip to content

Commit b93c2f6

Browse files
author
epriestley
committedMay 26, 2014
Fix two Passphrase credential type issues
Summary: Fixes T4991. Two issues: - These error messages pass an object to "%s", when they mean to pass a type constant. - The check for noncreatable credentials is incorrectly in the "edit" branch of the controller. Test Plan: - Edited a "SSH Key on disk" credential. - Tried to create a credential with a bogus type. Reviewers: btrahan, joshuaspence Reviewed By: joshuaspence Subscribers: epriestley Maniphest Tasks: T4991 Differential Revision: https://secure.phabricator.com/D9299
1 parent b7a8c0b commit b93c2f6

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed
 

‎src/applications/passphrase/controller/PassphraseCredentialEditController.php

+19-13
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,18 @@ public function processRequest() {
2626
return new Aphront404Response();
2727
}
2828

29-
$type = PassphraseCredentialType::getTypeByConstant(
30-
$credential->getCredentialType());
31-
if (!$type) {
32-
throw new Exception(pht('Credential has invalid type "%s"!', $type));
33-
}
34-
35-
if (!$type->isCreateable()) {
36-
throw new Exception(
37-
pht('Credential has noncreateable type "%s"!', $type));
38-
}
29+
$type = $this->getCredentialType($credential->getCredentialType());
3930

4031
$is_new = false;
4132
} else {
4233
$type_const = $request->getStr('type');
43-
$type = PassphraseCredentialType::getTypeByConstant($type_const);
44-
if (!$type) {
45-
return new Aphront404Response();
34+
$type = $this->getCredentialType($type_const);
35+
36+
if (!$type->isCreateable()) {
37+
throw new Exception(
38+
pht(
39+
'Credential has noncreateable type "%s"!',
40+
$credential->getCredentialType()));
4641
}
4742

4843
$credential = PassphraseCredential::initializeNewCredential($viewer)
@@ -358,4 +353,15 @@ public function processRequest() {
358353
));
359354
}
360355

356+
private function getCredentialType($type_const) {
357+
$type = PassphraseCredentialType::getTypeByConstant($type_const);
358+
359+
if (!$type) {
360+
throw new Exception(
361+
pht('Credential has invalid type "%s"!', $type_const));
362+
}
363+
364+
return $type;
365+
}
366+
361367
}

0 commit comments

Comments
 (0)
Failed to load comments.