11package plugin
22
33import (
4+ "os"
45 "os/exec"
5- "os"
6- "path/filepath"
7- "testing"
6+ "path/filepath"
7+ "testing"
88
9- "github.com/stretchr/testify/assert"
9+ "github.com/stretchr/testify/assert"
1010)
1111
1212const dummyPluginCode = `package main
@@ -21,32 +21,32 @@ func main() {
2121
2222 action := req["action"].(string)
2323 if action == "encrypt" {
24- fmt.Println("{\"ciphertext\": \"cifra-secreta \"}")
24+ fmt.Println("{\"ciphertext\": \"secret_cypher \"}")
2525 } else if action == "decrypt" {
26- fmt.Println("{\"plaintext\": \"dGV4dG8tY2xhcm8 =\"}")
26+ fmt.Println("{\"plaintext\": \"cGxhaW4tYXMtZGF5Cg= =\"}")
2727 }
2828}
2929`
3030
3131func TestPluginIPC (t * testing.T ) {
32- tmpDir := t .TempDir ()
33- pluginPath := filepath .Join (tmpDir , "sops-plugin-dummy" )
32+ tmpDir := t .TempDir ()
33+ pluginPath := filepath .Join (tmpDir , "sops-plugin-dummy" )
3434
35- srcFile := filepath .Join (tmpDir , "main.go" )
36- os .WriteFile (srcFile , []byte (dummyPluginCode ), 0644 )
35+ srcFile := filepath .Join (tmpDir , "main.go" )
36+ os .WriteFile (srcFile , []byte (dummyPluginCode ), 0o644 )
3737
38- err := exec .Command ("go" , "build" , "-o" , pluginPath , srcFile ).Run ()
39- assert .NoError (t , err , "failed to compile dummy plugin" )
38+ err := exec .Command ("go" , "build" , "-o" , pluginPath , srcFile ).Run ()
39+ assert .NoError (t , err , "failed to compile dummy plugin" )
4040
41- t .Setenv ("PATH" , tmpDir + string (os .PathListSeparator )+ os .Getenv ("PATH" ))
41+ t .Setenv ("PATH" , tmpDir + string (os .PathListSeparator )+ os .Getenv ("PATH" ))
4242
43- key := NewMasterKey ("dummy" , map [string ]any {"my_config" : "value" }, "10s" , "dummy" )
43+ key := NewMasterKey ("dummy" , map [string ]any {"my_config" : "value" }, "10s" , "dummy" )
4444
45- err = key .Encrypt ([]byte ("texto-claro " ))
46- assert .NoError (t , err )
47- assert .Equal (t , "secret_cypher" , string (key .EncryptedDataKey ()))
45+ err = key .Encrypt ([]byte ("plain-as-day \n " ))
46+ assert .NoError (t , err )
47+ assert .Equal (t , "secret_cypher" , string (key .EncryptedDataKey ()))
4848
49- plaintext , err := key .Decrypt ()
50- assert .NoError (t , err )
51- assert .Equal (t , "plain-as-day" , string (plaintext ))
49+ plaintext , err := key .Decrypt ()
50+ assert .NoError (t , err )
51+ assert .Equal (t , "plain-as-day\n " , string (plaintext ))
5252}
0 commit comments