-
Notifications
You must be signed in to change notification settings - Fork 5
Adding client authentication with public key fuction. #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 49 commits
20f480b
67629e3
ba21474
e9ce98c
8329e18
e56737c
a8e918f
b72ff81
7398602
fd9df89
7d92ca6
dc86ac5
8714d18
11a63f7
186568b
da2d781
e6e0984
2de4fcc
f7b44e9
eb79945
7519521
fdc200e
3171355
187827d
065295b
9d4d667
088e8f5
9a565bd
76a563c
c47e357
1329d57
de2b220
b586669
8d3282d
b88f005
8fd82e0
08c9355
819e639
4de652d
a0ba12b
5e76df6
c68c7c0
fe940a5
3d94237
d036635
ff7a886
299e1ac
1596b50
853ffa6
bb8bca2
533c3d0
8456dd5
6554021
d386fad
343c305
f4782d3
e4a0ecd
bc537e3
733384b
ee4c4ad
b78fbdc
3f9bed5
508f170
4155a3c
f9112cf
6b769a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ package tests | |
|
|
||
| import ( | ||
| "fmt" | ||
| "io/ioutil" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
@@ -21,6 +22,24 @@ func runConsoleCmd(instance_id string, t *testing.T) { | |
| RunCmdAndExpectFail(t, "sh", "-c", fmt.Sprintf("openvdc console %s -- false", instance_id)) | ||
| } | ||
|
|
||
| func runConsoleCmdWithPrivatekey(instance_id string, private_key_path string, t *testing.T, expect_fail bool) { | ||
| if expect_fail { | ||
| RunCmdAndExpectFail(t, "openvdc", "console", instance_id, "-i", private_key_path) | ||
| } else { | ||
| RunCmdAndReportFail(t, "openvdc", "console", instance_id, "-i", private_key_path) | ||
| } | ||
| } | ||
|
||
|
|
||
| func TestCmdConsole_ShowOptionAuthenticationNone(t *testing.T) { | ||
| stdout, _ := RunCmdAndReportFail(t, "openvdc", "run", "centos/7/lxc", `{"authentication_type":"none"}`) | ||
| instance_id := strings.TrimSpace(stdout.String()) | ||
| WaitInstance(t, 5*time.Minute, instance_id, "RUNNING", []string{"QUEUED", "STARTING"}) | ||
| runConsoleCmd(instance_id, t) | ||
| runConsoleCmdPiped(instance_id, t) | ||
| RunCmdWithTimeoutAndReportFail(t, 10, 5, "openvdc", "destroy", instance_id) | ||
| WaitInstance(t, 5*time.Minute, instance_id, "TERMINATED", nil) | ||
| } | ||
|
|
||
| func TestLXCCmdConsole_ShowOption(t *testing.T) { | ||
| stdout, _ := RunCmdAndReportFail(t, "openvdc", "run", "centos/7/lxc") | ||
| instance_id := strings.TrimSpace(stdout.String()) | ||
|
|
@@ -31,6 +50,37 @@ func TestLXCCmdConsole_ShowOption(t *testing.T) { | |
| WaitInstance(t, 5*time.Minute, instance_id, "TERMINATED", nil) | ||
| } | ||
|
|
||
| func TestLXCCmdConsole_AuthenticationPubkey(t *testing.T) { | ||
| // Make key pair by ssh-keygen | ||
| private_key_path := "./testRsa" | ||
| private_key_path2 := "./testRsa2" | ||
| _, _, err := RunCmd("ssh-keygen", "-t", "rsa", "-f", private_key_path, "-C", "", "-N", "") | ||
| if err != nil { | ||
| t.Fatalf("err: %s", err) | ||
| } | ||
| _, _, err = RunCmd("ssh-keygen", "-t", "rsa", "-f", private_key_path2, "-C", "", "-N", "") | ||
| if err != nil { | ||
| t.Fatalf("err: %s", err) | ||
| } | ||
|
|
||
| // Read public key | ||
| data, err := ioutil.ReadFile(private_key_path + ".pub") | ||
| if err != nil { | ||
| t.Fatalf("Can not read public key: %s\n", err.Error()) | ||
| } | ||
| public_key := strings.Replace(string(data), "\n", "", -1) | ||
| stdout, _ := RunCmdAndReportFail(t, "openvdc", "run", "centos/7/lxc", `{"authentication_type":"pub_key","ssh_public_key":"`+public_key+`"}`) | ||
|
|
||
| // runConsole() | ||
| instance_id := strings.TrimSpace(stdout.String()) | ||
| WaitInstance(t, 5*time.Minute, instance_id, "RUNNING", []string{"QUEUED", "STARTING"}) | ||
| runConsoleCmdWithPrivatekey(instance_id, private_key_path, t, false) | ||
| runConsoleCmdWithPrivatekey(instance_id, private_key_path2, t, true) // This can not be authenticated. | ||
| //vrunConsoleCmdPiped(instance_id, t) | ||
| RunCmdWithTimeoutAndReportFail(t, 10, 5, "openvdc", "destroy", instance_id) | ||
| WaitInstance(t, 5*time.Minute, instance_id, "TERMINATED", nil) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this a test for console authentication? It just starts an instance and then terminates it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added code to test the console. And change function name to TestCmdConsole_ShowOptionAuthenticationNone. |
||
| } | ||
|
|
||
| func TestQEMUCmdConsole_ShowOption(t *testing.T) { | ||
| stdout, _ := RunCmdAndReportFail(t, "openvdc", "run", "centos/7/qemu_ga") | ||
| instance_id := strings.TrimSpace(stdout.String()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "title": "CentOS7", | ||
| "template": { | ||
| "type": "vm/lxc", | ||
| "lxc_template": { | ||
| "openvdc": { | ||
| "distro": "centos", | ||
| "release": "7" | ||
| } | ||
| }, | ||
| "authentication_type": "none" | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is only called twice. Once with expect_fail = true and once with expect_fail = false.
Since only one line gets executed for each call, I think it's better to write those lines directly in the test instead of in a separate function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted runConsoleCmdWithPrivatekey and integrated to TestLXCCmdConsole_AuthenticationPubkey.