File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ out=" $( echo $1 | base64 -D) "
4
+
5
+ echo " meow $out " >&2
Original file line number Diff line number Diff line change
1
+ package plugin
2
+
3
+ import (
4
+ "bytes"
5
+ "encoding/base64"
6
+ "os"
7
+ "os/exec"
8
+ )
9
+
10
+ // Plugins work by passing in values on the command line, serialized using base64
11
+ // and reading responses out on stderr.
12
+ // This leaves stdin/stdout available for interaction by the user, to
13
+ // enter credentials or such
14
+
15
+ // Run runs the plugin
16
+ func Run (input []byte , plugin ... string ) ([]byte , error ) {
17
+ c := plugin [0 ]
18
+ args := plugin [1 :]
19
+
20
+ in := base64 .StdEncoding .EncodeToString (input )
21
+
22
+ args = append (args , in )
23
+
24
+ cmd := exec .Command (c , args ... )
25
+ var stderr bytes.Buffer
26
+ cmd .Stderr = & stderr
27
+
28
+ cmd .Stdout = os .Stdout
29
+ cmd .Stdin = os .Stdin
30
+
31
+ err := cmd .Run ()
32
+ if err != nil {
33
+ return nil , err
34
+ }
35
+ return stderr .Bytes (), nil
36
+ }
Original file line number Diff line number Diff line change
1
+ package plugin_test
2
+
3
+ import (
4
+ "math/rand"
5
+ "testing"
6
+
7
+ "github.com/brianm/epithet/pkg/plugin"
8
+ "github.com/stretchr/testify/assert"
9
+ "github.com/stretchr/testify/require"
10
+ )
11
+
12
+ func TestPlugin_BigInput (t * testing.T ) {
13
+ in := randStringBytes (8192 )
14
+ out , err := plugin .Run ([]byte (in ), "./plug.sh" )
15
+ require .NoError (t , err )
16
+
17
+ assert .Contains (t , string (out ), in )
18
+ assert .Contains (t , string (out ), "meow" )
19
+ }
20
+
21
+ const letterBytes = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
22
+
23
+ func randStringBytes (n int ) string {
24
+ b := make ([]byte , n )
25
+ for i := range b {
26
+ b [i ] = letterBytes [rand .Intn (len (letterBytes ))]
27
+ }
28
+ return string (b )
29
+ }
You can’t perform that action at this time.
0 commit comments