-
Notifications
You must be signed in to change notification settings - Fork 14
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
[#36] SSHKit.user errors because sudo is missing #51
Merged
pmeinhardt
merged 6 commits into
master
from
feature/36-sshkit-user-errors-because-sudo-is-missing
May 14, 2017
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8d61343
[#36] SSHKit.user errors because sudo is missing
pmeinhardt e4a5cee
Install "sudo" package for Alpine Docker image
pmeinhardt c79a3fd
Fix `SSHKit.user/2` test setup
pmeinhardt e11da3f
Update `SSHKit.Context.build/2` implementation
pmeinhardt 1299883
Rename passwordless-sudoers group
pmeinhardt e6ae35b
Remove TODO comment (handled in separate issue)
pmeinhardt 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 |
---|---|---|
|
@@ -9,7 +9,7 @@ defmodule SSHKit.SSHFunctionalTest do | |
test "opens a connection with username and password", %{hosts: [host]} do | ||
options = [port: host.port, user: host.user, password: host.password] | ||
{:ok, conn} = SSH.connect(host.ip, Keyword.merge(@defaults, options)) | ||
{:ok, data, status} = SSH.run(conn, "whoami") | ||
{:ok, data, status} = SSH.run(conn, "id -un") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
assert [stdout: "#{host.user}\n"] == data | ||
assert 0 = status | ||
|
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 |
---|---|---|
|
@@ -5,21 +5,15 @@ defmodule SSHKitFunctionalTest do | |
|
||
use SSHKit.FunctionalCase, async: true | ||
|
||
@defaults [silently_accept_hosts: true] | ||
@defaults [silently_accept_hosts: true, timeout: 5000] | ||
|
||
def options(overrides) do | ||
Keyword.merge(@defaults, overrides) | ||
end | ||
|
||
def build_context(host) do | ||
SSHKit.context({ | ||
host.ip, | ||
options(port: host.port, | ||
user: host.user, | ||
password: host.password, | ||
timeout: 5000 | ||
) | ||
}) | ||
overrides = [port: host.port, user: host.user, password: host.password] | ||
SSHKit.context({host.ip, Keyword.merge(@defaults, overrides)}) | ||
end | ||
|
||
defp stdio(output, type) do | ||
|
@@ -33,42 +27,39 @@ defmodule SSHKitFunctionalTest do | |
|
||
@tag boot: 1 | ||
test "connects", %{hosts: [host]} do | ||
[{:ok, output, 0}] = SSHKit.run(build_context(host), "whoami") | ||
|
||
[{:ok, output, 0}] = SSHKit.run(build_context(host), "id -un") | ||
name = String.trim(stdout(output)) | ||
assert name == host.user | ||
end | ||
|
||
@tag boot: 1 | ||
test "run", %{hosts: [host]} do | ||
test "runs commands", %{hosts: [host]} do | ||
context = build_context(host) | ||
|
||
[{:ok, output, status}] = SSHKit.run(context, "pwd") | ||
assert status == 0 | ||
output = stdout(output) | ||
assert output == "/home/me\n" | ||
assert stdout(output) == "/home/me\n" | ||
|
||
[{:ok, output, status}] = SSHKit.run(context, "ls non-existing") | ||
assert status == 1 | ||
output = stderr(output) | ||
assert output =~ "ls: non-existing: No such file or directory" | ||
assert stderr(output) =~ "ls: non-existing: No such file or directory" | ||
|
||
[{:ok, output, status}] = SSHKit.run(context, "does-not-exist") | ||
assert status == 127 | ||
output = stderr(output) | ||
assert output =~ "'does-not-exist': No such file or directory" | ||
assert stderr(output) =~ "'does-not-exist': No such file or directory" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
end | ||
|
||
@tag boot: 1 | ||
test "env", %{hosts: [host]} do | ||
[{:ok, output, status}] = | ||
host | ||
|> build_context | ||
|> build_context() | ||
|> SSHKit.env(%{"PATH" => "$HOME/.rbenv/shims:$PATH", "NODE_ENV" => "production"}) | ||
|> SSHKit.run("env") | ||
|
||
assert status == 0 | ||
output = stdout(output) | ||
|
||
assert status == 0 | ||
assert output =~ "NODE_ENV=production" | ||
assert output =~ ~r/PATH=.*\/\.rbenv\/shims:/ | ||
end | ||
|
@@ -77,14 +68,17 @@ defmodule SSHKitFunctionalTest do | |
test "umask", %{hosts: [host]} do | ||
context = | ||
host | ||
|> build_context | ||
|> build_context() | ||
|> SSHKit.umask("077") | ||
SSHKit.run(context, "mkdir my_dir") | ||
SSHKit.run(context, "touch my_file") | ||
|
||
[{:ok, _, 0}] = SSHKit.run(context, "mkdir my_dir") | ||
[{:ok, _, 0}] = SSHKit.run(context, "touch my_file") | ||
|
||
[{:ok, output, status}] = SSHKit.run(context, "ls -la") | ||
|
||
assert status == 0 | ||
output = stdout(output) | ||
|
||
assert status == 0 | ||
assert output =~ ~r/drwx--S---\s+2\s+me\s+me\s+4096.+my_dir/ | ||
assert output =~ ~r/-rw-------\s+1\s+me\s+me\s+0.+my_file/ | ||
end | ||
|
@@ -97,23 +91,25 @@ defmodule SSHKitFunctionalTest do | |
|> SSHKit.path("/var/log") | ||
|
||
[{:ok, output, status}] = SSHKit.run(context, "pwd") | ||
assert status == 0 | ||
output = stdout(output) | ||
|
||
assert status == 0 | ||
assert output == "/var/log\n" | ||
end | ||
|
||
@tag skip: true # it produces an error: "sudo not found" on stderr | ||
@tag boot: 1 | ||
test "user", %{hosts: [host]} do | ||
adduser(host, "despicable_me") | ||
add_user_to_group(host, host.user, "passwordless-sudoers") | ||
|
||
context = | ||
host | ||
|> build_context | ||
|> build_context() | ||
|> SSHKit.user("despicable_me") | ||
|
||
[{:ok, output, status}] = SSHKit.run(context, "whoami") | ||
[{:ok, output, status}] = SSHKit.run(context, "id -un") | ||
output = stdout(output) | ||
|
||
assert output == "despicable_me\n" | ||
assert status == 0 | ||
end | ||
|
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
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.
only this match of
sudo/3
is ever used, right?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.
Errr, nope. Unless I missed something, the context may hold any combination of
:user
and:group
being present or not present.Example:
Here, context has a user, but no group set.
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.
ah, you're right. i just misread the code yesterday evening. let's act as if i never wrote this comment ;)