Added 'SSHPublicKeyUrlEncoded()' to comm.Config.
This allows us to get a URL encoded string representing the SSH public key. This is needed because the key will have spaces when it is in authorized_keys format.
This commit is contained in:
parent
459bd1ea7a
commit
7b857929ab
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
|
@ -329,3 +330,9 @@ func (c *Config) prepareWinRM(ctx *interpolate.Context) []error {
|
|||
|
||||
return errs
|
||||
}
|
||||
|
||||
// SSHPublicKeyUrlEncoded returns a string representing the SSH public key
|
||||
// encoded in URL format.
|
||||
func (c *Config) SSHPublicKeyUrlEncoded() string {
|
||||
return url.PathEscape(string(c.SSHPublicKey))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package communicator
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
@ -136,6 +137,23 @@ func TestConfig_winrm(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestConfig_SSHPublicKeyUrlEncoded(t *testing.T) {
|
||||
c := &Config{
|
||||
SSHPublicKey: []byte("ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBADulbdHCjXhsH8wGtyLhhi3qVvX6M0tGgtousr/DzArwf2KX0L2Zm1OZfqMWFCrSVD743OFY60YL5CGsN9/PVQP7gApll5yTWyaQJu8lReptR5TMnUDn0u3mJN/QRT5Zs8qS5J5Q3WhXwaMF96kSuu+MwXrBnl8sK+bwxOKQtlKJXowcw==\n"),
|
||||
}
|
||||
|
||||
encoded := c.SSHPublicKeyUrlEncoded()
|
||||
|
||||
decoded, err := url.PathUnescape(encoded)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if decoded != string(c.SSHPublicKey) {
|
||||
t.Fatal("resulting public key does not match original public key")
|
||||
}
|
||||
}
|
||||
|
||||
func testContext(t *testing.T) *interpolate.Context {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue