-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #11583 - ehuss:container-tests, r=epage
Add network container tests This adds some tests which use Docker containers to provide HTTPS and SSH servers. This should help with validating that Cargo's networking and security are working correctly. It can also potentially be used in the future for other tests that require more complex setups. These tests are only run on Linux in CI. macOS does not have Docker there, and the Windows Docker does not support Linux containers. The tests should work on macOS if you run them locally with Docker Desktop installed. The SSH tests do not work on Windows due to issues with ssh-agent, but the HTTPS tests should work with Docker Desktop. These tests require an opt-in environment variable to run: * `CARGO_PUBLIC_NETWORK_TESTS=1` — This is for tests that contact the public internet. * `CARGO_CONTAINER_TESTS=1` — This is for tests that use Docker.
- Loading branch information
Showing
19 changed files
with
1,136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM httpd:2.4-alpine | ||
|
||
RUN apk add --no-cache git git-daemon openssl | ||
|
||
COPY bar /repos/bar | ||
WORKDIR /repos/bar | ||
RUN git config --global user.email "testuser@example.com" &&\ | ||
git config --global user.name "Test User" &&\ | ||
git init -b master . &&\ | ||
git add Cargo.toml src &&\ | ||
git commit -m "Initial commit" &&\ | ||
mv .git ../bar.git &&\ | ||
cd ../bar.git &&\ | ||
git config --bool core.bare true &&\ | ||
rm -rf ../bar | ||
WORKDIR / | ||
|
||
EXPOSE 443 | ||
|
||
WORKDIR /usr/local/apache2/conf | ||
COPY httpd-cargo.conf . | ||
RUN cat httpd-cargo.conf >> httpd.conf | ||
RUN openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \ | ||
-keyout server.key -out server.crt \ | ||
-subj "/emailAddress=webmaster@example.com/C=US/ST=California/L=San Francisco/O=Rust/OU=Cargo/CN=127.0.0.1" | ||
WORKDIR / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
name = "bar" | ||
version = "1.0.0" | ||
edition = "2021" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Intentionally blank. |
12 changes: 12 additions & 0 deletions
12
crates/cargo-test-support/containers/apache/httpd-cargo.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
SetEnv GIT_PROJECT_ROOT /repos | ||
SetEnv GIT_HTTP_EXPORT_ALL | ||
ScriptAlias /repos /usr/libexec/git-core/git-http-backend/ | ||
LoadModule cgid_module modules/mod_cgid.so | ||
|
||
<Files "git-http-backend"> | ||
Require all granted | ||
</Files> | ||
|
||
Include conf/extra/httpd-ssl.conf | ||
LoadModule ssl_module modules/mod_ssl.so | ||
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
FROM alpine:3.17 | ||
|
||
RUN apk add --no-cache openssh git | ||
RUN ssh-keygen -A | ||
|
||
RUN addgroup -S testuser && adduser -S testuser -G testuser -s /bin/ash | ||
# NOTE: Ideally the password should be set to *, but I am uncertain how to do | ||
# that in alpine. It shouldn't matter since PermitEmptyPasswords is "no". | ||
RUN passwd -u testuser | ||
|
||
RUN mkdir /repos && chown testuser /repos | ||
COPY --chown=testuser:testuser bar /repos/bar | ||
USER testuser | ||
WORKDIR /repos/bar | ||
RUN git config --global user.email "testuser@example.com" &&\ | ||
git config --global user.name "Test User" &&\ | ||
git init -b master . &&\ | ||
git add Cargo.toml src &&\ | ||
git commit -m "Initial commit" &&\ | ||
mv .git ../bar.git &&\ | ||
cd ../bar.git &&\ | ||
git config --bool core.bare true &&\ | ||
rm -rf ../bar | ||
WORKDIR / | ||
USER root | ||
|
||
EXPOSE 22 | ||
|
||
ENTRYPOINT ["/usr/sbin/sshd", "-D", "-E", "/var/log/auth.log"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
name = "bar" | ||
version = "1.0.0" | ||
edition = "2021" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Intentionally blank. |
Oops, something went wrong.