]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1286650 - Add option to scripts/issue-api-key.pl to specify an API key explicitly...
authorMark Côté <mcote@alumni.uwaterloo.ca>
Wed, 13 Jul 2016 21:16:01 +0000 (17:16 -0400)
committerMark Côté <mcote@alumni.uwaterloo.ca>
Wed, 13 Jul 2016 21:16:01 +0000 (17:16 -0400)
This is useful for testing, so we don't have to store a randomly generated
key for the duration of the test; instead we can hardcode one in the tests.

Bugzilla/User/APIKey.pm
scripts/issue-api-key.pl

index d89203e68b6f299d80f72c3e55ccadb9ded23da7..500f0ad59a4236e5ecb1db52d7c58e040604b733 100644 (file)
@@ -88,6 +88,12 @@ sub _check_app_id {
 
     return $app_id;
 }
+
+sub create_special {
+    my ($class, @args) = @_;
+    local VALIDATORS->{api_key} = sub { return $_[1] };
+    return $class->create(@args);
+}
 1;
 
 __END__
index 35abb92006332b5cc8bb064292d5572d4b14f6f8..334cddeaa8b7c2482bba0ada1e06c3829973bfaf 100755 (executable)
@@ -22,19 +22,26 @@ use Bugzilla::User::APIKey;
 Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
 
 my $login = shift
-    or die "syntax: $0 bugzilla-login [description]\n";
+    or die "syntax: $0 bugzilla-login [description] [api key]\n";
 my $description = shift;
+my $given_api_key = shift;
+my $api_key;
 
 my $user = Bugzilla::User->check({ name => $login });
 
 my $params = {
     user_id     => $user->id,
     description => $description,
+    api_key     => $given_api_key,
 };
 
 if ($description && $description eq 'mozreview') {
     $params->{app_id} = Bugzilla->params->{mozreview_app_id} // '';
 }
 
-my $api_key = Bugzilla::User::APIKey->create($params);
+if ($given_api_key) {
+    $api_key = Bugzilla::User::APIKey->create_special($params);
+} else {
+    $api_key = Bugzilla::User::APIKey->create($params);
+}
 say $api_key->api_key;