-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quote systemd DefaultEnvironment Proxy values #23674
Merged
openshift-merge-bot
merged 1 commit into
containers:main
from
feloy:fix-23277/quote-default-env
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package proxyenv | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_getProxyScript(t *testing.T) { | ||
type env struct { | ||
name string | ||
value string | ||
} | ||
type args struct { | ||
isWSL bool | ||
envs []env | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "all vars set", | ||
args: args{ | ||
isWSL: false, | ||
envs: []env{ | ||
{ | ||
name: "http_proxy", | ||
value: "proxy1", | ||
}, | ||
{ | ||
name: "https_proxy", | ||
value: "sproxy1", | ||
}, | ||
{ | ||
name: "no_proxy", | ||
value: "no1,no2", | ||
}, | ||
}, | ||
}, | ||
want: `#!/bin/bash | ||
|
||
SYSTEMD_CONF=/etc/systemd/system.conf.d/default-env.conf | ||
ENVD_CONF=/etc/environment.d/default-env.conf | ||
PROFILE_CONF=/etc/profile.d/default-env.sh | ||
|
||
mkdir -p /etc/profile.d /etc/environment.d /etc/systemd/system.conf.d/ | ||
rm -f $SYSTEMD_CONF $ENVD_CONF $PROFILE_CONF | ||
|
||
echo "[Manager]" >> $SYSTEMD_CONF | ||
for proxy in "http_proxy=proxy1" "https_proxy=sproxy1" "no_proxy=no1,no2"; do | ||
printf "DefaultEnvironment=\"%s\"\n" "$proxy" >> $SYSTEMD_CONF | ||
printf "%q\n" "$proxy" >> $ENVD_CONF | ||
printf "export %q\n" "$proxy" >> $PROFILE_CONF | ||
done | ||
|
||
systemctl daemon-reload | ||
`, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
for _, e := range tt.args.envs { | ||
t.Setenv(e.name, e.value) | ||
} | ||
got := getProxyScript(tt.args.isWSL) | ||
buf := new(bytes.Buffer) | ||
_, err := buf.ReadFrom(got) | ||
assert.NoError(t, err) | ||
str := buf.String() | ||
assert.Equal(t, tt.want, str) | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break if the vars contains a quote, I guess I am fine to trade quote is broken vs command is broken because the later is actually used in these vars while the quote most likely is never used.
However please fix the test and add a comma there
podman/pkg/machine/e2e/proxy_test.go
Line 79 in 77f5b4d