sshtest

package module
v0.0.0-...-f19fe8b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2022 License: BSD-3-Clause Imports: 2 Imported by: 0

README

SSH Test Library

SSH Testing in GO can, at time, be troublesome. This is a helper library for users to test functions that do SSH to another host

Installation

sshtest is compatible with modern Go releases in module mode, with Go installed:

go get github.com/metarsit/sshtest

Usage

Below is an example of the usage of the library

import (
	"testing"

	"github.com/metarsit/sshtest"
	"gotest.tools/v3/assert"
)

func TestYourSSHFunction(t *testing.T) {
    // Example of an IP address for localhost
    const (
        addr      = "127.0.0.1:2222"
        returnMsg = "some_return"
    )
    
    hp := ssh.NewHoneyPot(addr)
    
    // Close the Honeypot when goes out of scope
    t.Cleanup(func() {
        hp.Close()
    })
    
    // Run Honeypot in the background
    go func() {
        hp.ListenAndServe()
    }()

    // Set output
    hp.SetReturnString(returnMsg)

    // Call the function that talks to the addr specified
    someReturn, someError := YourSSHFunction(addr)

    // Assert the returns
    assert.NilError(t, someError)
    assert.Equal(t, someReturn, returnMsg)
}
Authentication

No password is required to access honeypot

Pre-requisite

  • docker
  • make
  • go

Credit

Special thanks to gliderlabs for creating and providing us with ssh library

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HoneyPot

type HoneyPot struct {
	// contains filtered or unexported fields
}

HoneyPot encapsulates the initialized struct

func NewHoneyPot

func NewHoneyPot(addr string) *HoneyPot

NewHoneyPot takes in IP address to be used for honeypot

func (*HoneyPot) Close

func (h *HoneyPot) Close() error

Close returns any error returned from closing the Server's underlying Listener(s).

func (*HoneyPot) ListenAndServe

func (h *HoneyPot) ListenAndServe() error

ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle incoming connections

func (*HoneyPot) SetReturnString

func (h *HoneyPot) SetReturnString(str string)

SetReturnString takes in a string and set it as the response from the server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL