Skip to content

Commit

Permalink
fix: deprecation and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Nov 12, 2024
1 parent 2274d4c commit 1111274
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
services:
# Label used to access the service container
sshtest:
image: placeos/ssh-test:latest
image: testcontainers/sshd:1.2.0
env:
ROOT_PASS: somepassword
PASSWORD: somepassword

steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ end
In order to run test suite you need to pull and run the following docker container:

```
$ docker pull tutum/ubuntu:trusty
$ docker run -d -p 2222:22 -e AUTHORIZED_KEYS="`cat ./spec/keys/id_rsa.pub`" tutum/ubuntu:trusty
docker compose up -d
```

Have a look at the docker-compose.yml file for configuration details

# License

MIT clause - see LICENSE for more details.
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
sshd:
image: testcontainers/sshd:1.2.0
environment:
PASSWORD: "somepassword"
ports:
- 10022:22
17 changes: 7 additions & 10 deletions spec/ssh2_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ require "../src/ssh2"
require "spec"

SPEC_SSH_HOST = ENV["SPEC_SSH_HOST"]? || "localhost"
SPEC_SSH_PORT = ENV["CI"]? ? 22 : 2222
SPEC_SSH_PORT = ENV["CI"]? ? 22 : 10022

def connect_ssh
SSH2::Session.open(SPEC_SSH_HOST, SPEC_SSH_PORT) do |session|
if ENV["CI"]?
session.login("root", "somepassword")
else
session.login_with_pubkey("root", "./spec/keys/id_rsa", "./spec/keys/id_rsa.pub")
end
session.login("root", "somepassword")
session.authenticated?.should be_true
yield session
end
Expand All @@ -30,6 +26,7 @@ describe SSH2 do

it "should be able to connect in interactive mode" do
SSH2::Session.open(SPEC_SSH_HOST, SPEC_SSH_PORT) do |session|
pending!("container doesn't support interactive login...")
session.interactive_login("root") { "somepassword" }

session.open_session do |channel|
Expand Down Expand Up @@ -117,22 +114,22 @@ describe SSH2::SFTP do
it "should be able to list directory" do
connect_ssh do |ssh|
ssh.sftp_session do |sftp|
dir = sftp.open_dir(".")
dir = sftp.open_dir("/usr/bin/")
files = dir.ls
files.empty?.should be_false
files.includes?(".bashrc").should be_true
files.includes?("scp").should be_true
end
end
end

it "should be able to retrieve a file" do
connect_ssh do |ssh|
ssh.sftp_session do |sftp|
file = sftp.open(".bashrc")
file = sftp.open("/etc/resolv.conf")
attrs = file.fstat
attrs.atime.should be_a(Time)
attrs.permissions.to_s(8).should eq("100644")
file.gets_to_end.should match(/.bashrc/)
file.gets_to_end.should match(/nameserver/)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/session.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SSH2::Session
handshake
end

@handle : Pointer(Void) = Pointer(Void).new(0)
@handle : Pointer(Void) = Pointer(Void).null

def self.connect(host : String, port = 22)
socket = TCPSocket.new(host, port)
Expand Down

0 comments on commit 1111274

Please sign in to comment.