add challenger welcome text to e2e case

This commit is contained in:
Boshi Lian 2018-02-19 22:17:21 +08:00
parent dc975cbda6
commit 7b7dc9d778
8 changed files with 55 additions and 42 deletions

View file

@ -12,7 +12,7 @@ import (
type plugin struct {
Config struct {
OutputDir string `long:"auditor-typescriptlogger-outputdir" default:"/var/sshpiper" description:"Place where logged typescript files were saved" ini-name:"auditor-typescriptlogger-outputdir"`
OutputDir string `long:"auditor-typescriptlogger-outputdir" default:"/var/sshpiper" description:"Place where logged typescript files were saved" env:"SSHPIPERD_AUDITOR_TYPESCRIPTLOGGER_OUTPUTDIR" ini-name:"auditor-typescriptlogger-outputdir"`
}
}

View file

@ -70,5 +70,5 @@ func init() {
return
}
challenger.Register("pam", challenger.NewFromHandler("pam", pamChallenger, nil, nil))
challenger.Register("pam", challenger.NewFromHandler("pam", func() challenger.ChallengerHandler { return pamChallenger }, nil, nil))
}

View file

@ -5,10 +5,10 @@ import (
)
type plugin struct {
name string
init func(logger *log.Logger) error
opts interface{}
handler ChallengerHandler
name string
init func(logger *log.Logger) error
opts interface{}
gethandler func() ChallengerHandler
}
func (p *plugin) GetName() string {
@ -20,7 +20,7 @@ func (p *plugin) GetOpts() interface{} {
}
func (p *plugin) GetChallengerHandler() ChallengerHandler {
return p.handler
return p.gethandler()
}
func (p *plugin) Init(logger *log.Logger) error {
@ -32,11 +32,11 @@ func (p *plugin) Init(logger *log.Logger) error {
return nil
}
func NewFromHandler(name string, handler ChallengerHandler, opts interface{}, init func(glogger *log.Logger) error) Challenger {
func NewFromHandler(name string, gethandler func() ChallengerHandler, opts interface{}, init func(glogger *log.Logger) error) Challenger {
return &plugin{
name: name,
init: init,
opts: opts,
handler: handler,
name: name,
init: init,
opts: opts,
gethandler: gethandler,
}
}

View file

@ -22,10 +22,12 @@ func init() {
var h challenger.ChallengerHandler
config := &struct {
WelcomeText string `long:"challenger-welcometext" description:"Show a welcome text when connect to sshpiper server" ini-name:"challenger-welcometext"`
WelcomeText string `long:"challenger-welcometext" description:"Show a welcome text when connect to sshpiper server" env:"SSHPIPERD_CHALLENGER_WELCOMETEXT" ini-name:"challenger-welcometext"`
}{}
challenger.Register("welcometext", challenger.NewFromHandler("welcometext", h, config, func(logger *log.Logger) error {
challenger.Register("welcometext", challenger.NewFromHandler("welcometext", func() challenger.ChallengerHandler {
return h
}, config, func(logger *log.Logger) error {
h = makeWelcomeChallenger(config.WelcomeText)
return nil
}))

View file

@ -82,7 +82,7 @@ func main() {
piperdConfig
Logfile string `long:"log" description:"Logfile path. Leave empty or any error occurs will fall back to stdout" env:"SSHPIPERD_LOG_PATH" ini-name:"log-path"`
ConfigFile flags.Filename `long:"config" description:"Config file path. Higher priority than arg options and environment variables" default:"/etc/sshpiperd.ini" no-ini:"true"`
ConfigFile flags.Filename `long:"config" description:"Config file path. Higher priority than arg options and environment variables" default:"/etc/sshpiperd.ini" env:"SSHPIPERD_CONFIG_FILE" no-ini:"true"`
}{}
addOpt(parser, "sshpiperd", config)

View file

@ -17,6 +17,9 @@ services:
piper:
environment:
- "SSHPIPERD_WORKINGDIR_NOCHECKPERM=true"
- "SSHPIPERD_AUDITOR=typescript-logger"
- "SSHPIPERD_CHALLENGER=welcometext"
- "SSHPIPERD_CHALLENGER_WELCOMETEXT=hellopiper"
build: ../..
links:
- "host1:host1"
@ -34,7 +37,7 @@ services:
- names:/names
volumes:
workingdir:
workingdir:
localkey:
host1ssh:
names:

View file

@ -1,8 +1,5 @@
#!/bin/bash
#apt-get update
#apt-get install -y sshpass
mkdir -p /local
mkdir -p /workingdir/host{1,2}
@ -17,33 +14,42 @@ echo "root@host1" > /workingdir/host1/sshpiper_upstream
echo "root@host2" > /workingdir/host2/sshpiper_upstream
fail="\033[0;31mFAIL\033[0m"
succ="\033[0;32mSUCC\033[0m"
runtest(){
casename=$1
host=$2
rnd=`head -c 20 /dev/urandom | base64`
echo $rnd > /names/$host
rm -f /tmp/$host.stderr
t=$($3 2>/tmp/$host.stderr)
if [ "$t" != "$rnd" ];then
echo -e $casename $fail
else
echo -e $casename $succ
fi
grep $rnd /workingdir/$host/*
if [ $? -ne 0 ];then
echo -e "grep typescript logger" $fail
fi
grep "hellopiper" /tmp/$host.stderr
if [ $? -ne 0 ];then
echo -e "welcome text" $fail
fi
}
while true; do
casename="host1 with public key: "
rnd=`head -c 6 /dev/urandom | base64`
echo $rnd > /names/host1
t=`ssh host1@piper -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /local/id_rsa cat /names/host1`
runtest "host1 with public key:" "host1" "ssh host1@piper -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /local/id_rsa cat /names/host1"
runtest "host2 with password:" "host2" "sshpass -p root ssh host2@piper -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null cat /names/host2"
if [ "$t" != "$rnd" ];then
echo -e $casename $fail
else
echo -e $casename $succ
fi
casename="host2 with password"
rnd=`head -c 6 /dev/urandom | base64`
echo $rnd > /names/host2
t=`sshpass -p root ssh host2@piper -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null cat /names/host2`
if [ "$t" != "$rnd" ];then
echo -e $casename $fail
else
echo -e $casename $succ
fi
sleep 1
sleep 2
done

View file

@ -46,6 +46,8 @@ func startPiper(config *piperdConfig) {
logger.Printf("using additional challenger %s", config.ChallengerDriver)
ac.Init(logger)
logger.Printf("%v", ac.GetChallengerHandler())
piper.AdditionalChallenge = ac.GetChallengerHandler()
}