Merge "Test that the gpgkeys REST endpoints are correctly bound"
diff --git a/javatests/com/google/gerrit/acceptance/rest/AccountsRestApiBindingsIT.java b/javatests/com/google/gerrit/acceptance/rest/AccountsRestApiBindingsIT.java
index e5c16de..1a401b0 100644
--- a/javatests/com/google/gerrit/acceptance/rest/AccountsRestApiBindingsIT.java
+++ b/javatests/com/google/gerrit/acceptance/rest/AccountsRestApiBindingsIT.java
@@ -15,11 +15,19 @@
package com.google.gerrit.acceptance.rest;
import static com.google.gerrit.acceptance.rest.AbstractRestApiBindingsTest.Method.PUT;
+import static com.google.gerrit.gpg.testing.TestKeys.validKeyWithoutExpiration;
import static org.apache.http.HttpStatus.SC_METHOD_NOT_ALLOWED;
import com.google.common.collect.ImmutableList;
+import com.google.gerrit.acceptance.GerritConfig;
import com.google.gerrit.acceptance.UseSsh;
import com.google.gerrit.extensions.common.ChangeInput;
+import com.google.gerrit.gpg.testing.TestKey;
+import com.google.gerrit.server.ServerInitiated;
+import com.google.gerrit.server.account.AccountsUpdate;
+import com.google.gerrit.server.account.externalids.ExternalId;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
import org.junit.Test;
/**
@@ -30,6 +38,8 @@
* AbstractRestApiBindingsTest}).
*/
public class AccountsRestApiBindingsIT extends AbstractRestApiBindingsTest {
+ @Inject private @ServerInitiated Provider<AccountsUpdate> accountsUpdateProvider;
+
/**
* Account REST endpoints to be tested, each URL contains a placeholder for the account
* identifier.
@@ -80,7 +90,9 @@
RestCall.post("/accounts/%s/external.ids:delete"),
RestCall.get("/accounts/%s/oauthtoken"),
RestCall.get("/accounts/%s/capabilities"),
- RestCall.get("/accounts/%s/capabilities/viewPlugins"));
+ RestCall.get("/accounts/%s/capabilities/viewPlugins"),
+ RestCall.get("/accounts/%s/gpgkeys"),
+ RestCall.post("/accounts/%s/gpgkeys"));
/**
* Email REST endpoints to be tested, each URL contains a placeholders for the account and email
@@ -96,6 +108,17 @@
RestCall.delete("/accounts/%s/emails/%s"));
/**
+ * GPG key REST endpoints to be tested, each URL contains a placeholders for the account
+ * identifier and the GPG key identifier.
+ */
+ private static final ImmutableList<RestCall> GPG_KEY_ENDPOINTS =
+ ImmutableList.of(
+ RestCall.get("/accounts/%s/gpgkeys/%s"),
+
+ // GPG key deletion must be tested last
+ RestCall.delete("/accounts/%s/gpgkeys/%s"));
+
+ /**
* SSH key REST endpoints to be tested, each URL contains a placeholders for the account and SSH
* key identifier.
*/
@@ -128,6 +151,30 @@
}
@Test
+ @GerritConfig(name = "receive.enableSignedPush", value = "true")
+ public void gpgKeyEndpoints() throws Exception {
+ TestKey key = validKeyWithoutExpiration();
+ String id = key.getKeyIdString();
+
+ String email = "test1@example.com"; // email that is hard-coded in the test GPG key
+ accountsUpdateProvider
+ .get()
+ .update(
+ "Add Email",
+ admin.getId(),
+ u ->
+ u.addExternalId(
+ ExternalId.createWithEmail(name("test"), email, admin.getId(), email)));
+
+ setApiUser(admin);
+ gApi.accounts()
+ .self()
+ .putGpgKeys(ImmutableList.of(key.getPublicKeyArmored()), ImmutableList.of());
+
+ execute(GPG_KEY_ENDPOINTS, "self", id);
+ }
+
+ @Test
@UseSsh
public void sshKeyEndpoints() throws Exception {
String sshKeySeq = Integer.toString(gApi.accounts().self().listSshKeys().size());