diff options
author | Luca Milanesio <luca.milanesio@gmail.com> | 2019-12-13 21:51:03 +0000 |
---|---|---|
committer | Luca Milanesio <luca.milanesio@gmail.com> | 2019-12-13 22:40:25 +0000 |
commit | d2b12082143926e4feb362c8723602d6ef39e2c3 (patch) | |
tree | e69c36ac777b853c408b550fb1f79103f06309d2 | |
parent | 001b64e62a9a13e797a12a42ed63fad34515bcb0 (diff) |
Test Git/HTTP Servlet when SSH is enabled
The way Git/HTTP threads are managed is different when
the SSH daemon is enabled. Make sure that all the Git/HTTP
operations are working as expected by enabling also SSHD.
In order to reuse the GitOverHttpServletIT logic, introduce
a new abstract class and add it to the common library used
by all git tests in Bazel BUILD file.
Change-Id: I879881b6db5f4295c1c889a764e0c31d369463f7
4 files changed, 90 insertions, 53 deletions
diff --git a/javatests/com/google/gerrit/acceptance/git/AbstractGitOverHttpServlet.java b/javatests/com/google/gerrit/acceptance/git/AbstractGitOverHttpServlet.java new file mode 100644 index 0000000000..2f54f88508 --- /dev/null +++ b/javatests/com/google/gerrit/acceptance/git/AbstractGitOverHttpServlet.java @@ -0,0 +1,68 @@ +// Copyright (C) 2019 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.google.gerrit.acceptance.git; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.gerrit.server.AuditEvent; +import java.util.Collections; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.eclipse.jgit.transport.RefSpec; +import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; +import org.junit.Before; +import org.junit.Test; + +public class AbstractGitOverHttpServlet extends AbstractPushForReview { + + @Before + public void beforeEach() throws Exception { + CredentialsProvider.setDefault( + new UsernamePasswordCredentialsProvider(admin.username, admin.httpPassword)); + selectProtocol(AbstractPushForReview.Protocol.HTTP); + auditService.clearEvents(); + } + + @Test + public void receivePackAuditEventLog() throws Exception { + testRepo + .git() + .push() + .setRemote("origin") + .setRefSpecs(new RefSpec("HEAD:refs/for/master")) + .call(); + + // Git smart protocol makes two requests: + // https://github.com/git/git/blob/master/Documentation/technical/http-protocol.txt + assertThat(auditService.auditEvents.size()).isEqualTo(2); + + AuditEvent e = auditService.auditEvents.get(1); + assertThat(e.who.getAccountId()).isEqualTo(admin.id); + assertThat(e.what).endsWith("/git-receive-pack"); + assertThat(e.params).isEmpty(); + } + + @Test + public void uploadPackAuditEventLog() throws Exception { + testRepo.git().fetch().call(); + + assertThat(auditService.auditEvents.size()).isEqualTo(1); + + AuditEvent e = auditService.auditEvents.get(0); + assertThat(e.who.toString()).isEqualTo("ANONYMOUS"); + assertThat(e.params.get("service")) + .containsExactlyElementsIn(Collections.singletonList("git-upload-pack")); + assertThat(e.what).endsWith("service=git-upload-pack"); + } +} diff --git a/javatests/com/google/gerrit/acceptance/git/BUILD b/javatests/com/google/gerrit/acceptance/git/BUILD index 5c35cc7904..1ecfd43a91 100644 --- a/javatests/com/google/gerrit/acceptance/git/BUILD +++ b/javatests/com/google/gerrit/acceptance/git/BUILD @@ -14,7 +14,7 @@ load("//javatests/com/google/gerrit/acceptance:tests.bzl", "acceptance_tests") java_library( name = "push_for_review", testonly = True, - srcs = ["AbstractPushForReview.java"], + srcs = glob(["Abstract*.java"]), deps = [ "//java/com/google/gerrit/acceptance:lib", "//java/com/google/gerrit/mail", diff --git a/javatests/com/google/gerrit/acceptance/git/GitOverHttpServletIT.java b/javatests/com/google/gerrit/acceptance/git/GitOverHttpServletIT.java index 42e046ad02..e9f9b82954 100644 --- a/javatests/com/google/gerrit/acceptance/git/GitOverHttpServletIT.java +++ b/javatests/com/google/gerrit/acceptance/git/GitOverHttpServletIT.java @@ -14,55 +14,4 @@ package com.google.gerrit.acceptance.git; -import static com.google.common.truth.Truth.assertThat; - -import com.google.gerrit.server.AuditEvent; -import java.util.Collections; -import org.eclipse.jgit.transport.CredentialsProvider; -import org.eclipse.jgit.transport.RefSpec; -import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; -import org.junit.Before; -import org.junit.Test; - -public class GitOverHttpServletIT extends AbstractPushForReview { - - @Before - public void beforeEach() throws Exception { - CredentialsProvider.setDefault( - new UsernamePasswordCredentialsProvider(admin.username, admin.httpPassword)); - selectProtocol(AbstractPushForReview.Protocol.HTTP); - auditService.clearEvents(); - } - - @Test - public void receivePackAuditEventLog() throws Exception { - testRepo - .git() - .push() - .setRemote("origin") - .setRefSpecs(new RefSpec("HEAD:refs/for/master")) - .call(); - - // Git smart protocol makes two requests: - // https://github.com/git/git/blob/master/Documentation/technical/http-protocol.txt - assertThat(auditService.auditEvents.size()).isEqualTo(2); - - AuditEvent e = auditService.auditEvents.get(1); - assertThat(e.who.getAccountId()).isEqualTo(admin.id); - assertThat(e.what).endsWith("/git-receive-pack"); - assertThat(e.params).isEmpty(); - } - - @Test - public void uploadPackAuditEventLog() throws Exception { - testRepo.git().fetch().call(); - - assertThat(auditService.auditEvents.size()).isEqualTo(1); - - AuditEvent e = auditService.auditEvents.get(0); - assertThat(e.who.toString()).isEqualTo("ANONYMOUS"); - assertThat(e.params.get("service")) - .containsExactlyElementsIn(Collections.singletonList("git-upload-pack")); - assertThat(e.what).endsWith("service=git-upload-pack"); - } -} +public class GitOverHttpServletIT extends AbstractGitOverHttpServlet {} diff --git a/javatests/com/google/gerrit/acceptance/git/GitOverHttpServletWithSshdEnabledIT.java b/javatests/com/google/gerrit/acceptance/git/GitOverHttpServletWithSshdEnabledIT.java new file mode 100644 index 0000000000..9b9372f8ce --- /dev/null +++ b/javatests/com/google/gerrit/acceptance/git/GitOverHttpServletWithSshdEnabledIT.java @@ -0,0 +1,20 @@ +// Copyright (C) 2019 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.google.gerrit.acceptance.git; + +import com.google.gerrit.acceptance.UseSsh; + +@UseSsh +public class GitOverHttpServletWithSshdEnabledIT extends AbstractGitOverHttpServlet {} |