forked from deis/deis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(deisctl): new config logic related to filesystem and base64 opera…
…tions
- Loading branch information
Gabriel Monroy
committed
Jan 15, 2015
1 parent
dbd42a7
commit bae0085
Showing
2 changed files
with
113 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/base64" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
) | ||
|
||
// TestConfigSSHPrivateKey ensures private keys are base64 encoded from file path | ||
func TestConfigSSHPrivateKey(t *testing.T) { | ||
|
||
f, err := writeTempFile("private-key") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
val, err := valueForPath("/deis/platform/sshPrivateKey", f.Name()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
encoded := base64.StdEncoding.EncodeToString([]byte("private-key")) | ||
|
||
if val != encoded { | ||
t.Fatalf("expected: %v, got: %v", encoded, val) | ||
} | ||
} | ||
|
||
func TestConfigRouterKey(t *testing.T) { | ||
|
||
f, err := writeTempFile("router-key") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
val, err := valueForPath("/deis/router/sslKey", f.Name()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if val != "router-key" { | ||
t.Fatalf("expected: router-key, got: %v", val) | ||
} | ||
|
||
} | ||
|
||
func TestConfigRouterCert(t *testing.T) { | ||
|
||
f, err := writeTempFile("router-cert") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
val, err := valueForPath("/deis/router/sslCert", f.Name()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if val != "router-cert" { | ||
t.Fatalf("expected: router-cert, got: %v", val) | ||
} | ||
|
||
} | ||
|
||
func writeTempFile(data string) (*os.File, error) { | ||
f, err := ioutil.TempFile("", "deisctl") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
f.Write([]byte(data)) | ||
defer f.Close() | ||
|
||
return f, nil | ||
} |