| // Copyright (C) 2020 The Android Open Source Project |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package com.googlesource.gerrit.plugins.replication.pull; |
| |
| import static com.google.common.truth.Truth.assertThat; |
| |
| import com.google.gerrit.acceptance.PushOneCommit.Result; |
| import com.google.gerrit.acceptance.SkipProjectClone; |
| import com.google.gerrit.acceptance.TestPlugin; |
| import com.google.gerrit.acceptance.UseLocalDisk; |
| import com.google.gerrit.acceptance.config.GerritConfig; |
| import com.google.gerrit.extensions.events.GitReferenceUpdatedListener; |
| import java.io.IOException; |
| import java.util.List; |
| import java.util.Optional; |
| import org.eclipse.jgit.lib.ObjectId; |
| import org.eclipse.jgit.lib.Ref; |
| import org.eclipse.jgit.lib.Repository; |
| import org.eclipse.jgit.revwalk.RevCommit; |
| import org.eclipse.jgit.transport.ReceiveCommand; |
| import org.junit.Test; |
| |
| @SkipProjectClone |
| @UseLocalDisk |
| @TestPlugin( |
| name = "pull-replication", |
| sysModule = "com.googlesource.gerrit.plugins.replication.pull.PullReplicationModule", |
| httpModule = "com.googlesource.gerrit.plugins.replication.pull.api.HttpModule") |
| public class PullReplicationWithGitHttpTransportProtocolIT extends PullReplicationSetupBase { |
| |
| @Override |
| protected void setReplicationSource( |
| String remoteName, List<String> replicaSuffixes, Optional<String> project) |
| throws IOException { |
| List<String> fetchUrls = |
| buildReplicaURLs(replicaSuffixes, s -> adminRestSession.url() + "/${name}" + s + ".git"); |
| config.setStringList("remote", remoteName, "url", fetchUrls); |
| config.setString("remote", remoteName, "apiUrl", adminRestSession.url()); |
| config.setString("remote", remoteName, "fetch", "+refs/*:refs/*"); |
| config.setInt("remote", remoteName, "timeout", 600); |
| config.setInt("remote", remoteName, "replicationDelay", TEST_REPLICATION_DELAY); |
| project.ifPresent(prj -> config.setString("remote", remoteName, "projects", prj)); |
| config.setBoolean("gerrit", null, "autoReload", true); |
| config.save(); |
| } |
| |
| @Override |
| public void setUpTestPlugin() throws Exception { |
| setUpTestPlugin(false); |
| } |
| |
| @Test |
| @GerritConfig(name = "gerrit.instanceId", value = TEST_REPLICATION_REMOTE) |
| public void shouldReplicateWithBasicAuthentication() throws Exception { |
| runTest(); |
| } |
| |
| @Test |
| @GerritConfig(name = "gerrit.instanceId", value = TEST_REPLICATION_REMOTE) |
| @GerritConfig(name = "auth.bearerToken", value = "some-bearer-token") |
| public void shouldReplicateWithBearerTokenAuthentication() throws Exception { |
| runTest(); |
| } |
| |
| private void runTest() throws Exception { |
| testRepo = cloneProject(createTestProject(project + TEST_REPLICATION_SUFFIX)); |
| |
| Result pushResult = createChange(); |
| RevCommit sourceCommit = pushResult.getCommit(); |
| String sourceRef = pushResult.getPatchSet().refName(); |
| |
| ReplicationQueue pullReplicationQueue = getInstance(ReplicationQueue.class); |
| GitReferenceUpdatedListener.Event event = |
| new FakeGitReferenceUpdatedEvent( |
| project, |
| sourceRef, |
| ObjectId.zeroId().getName(), |
| sourceCommit.getId().getName(), |
| ReceiveCommand.Type.CREATE); |
| pullReplicationQueue.onGitReferenceUpdated(event); |
| |
| try (Repository repo = repoManager.openRepository(project)) { |
| waitUntil(() -> checkedGetRef(repo, sourceRef) != null); |
| |
| Ref targetBranchRef = getRef(repo, sourceRef); |
| assertThat(targetBranchRef).isNotNull(); |
| assertThat(targetBranchRef.getObjectId()).isEqualTo(sourceCommit.getId()); |
| } |
| } |
| } |