| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package fsdriver
- import (
- "reflect"
- "testing"
- )
- func TestGenSshdConfig(t *testing.T) {
- cases := []struct {
- config []string
- loginAccount string
- loginPassword string
- sshPort int
- expected []string
- }{
- {
- config: []string{
- "PermitRootLogin no",
- "PasswordAuthentication no",
- "# Port 22",
- },
- loginAccount: "root",
- loginPassword: "123456",
- sshPort: 22,
- expected: []string{
- "PermitRootLogin yes",
- "PasswordAuthentication yes",
- "# Port 22",
- },
- },
- {
- config: []string{
- "PermitRootLogin no",
- "PasswordAuthentication no",
- "#Port 22",
- },
- loginAccount: "yunion",
- loginPassword: "123456",
- sshPort: 22,
- expected: []string{
- "PermitRootLogin no",
- "PasswordAuthentication yes",
- "#Port 22",
- },
- },
- {
- config: []string{
- "PermitRootLogin no",
- "PasswordAuthentication no",
- "Port 22",
- },
- loginAccount: "yunion",
- loginPassword: "123456",
- sshPort: 9000,
- expected: []string{
- "PermitRootLogin no",
- "PasswordAuthentication yes",
- "Port 9000",
- },
- },
- {
- config: []string{
- "# PermitRootLogin no",
- "PasswordAuthentication no",
- "Port 22",
- },
- loginAccount: "root",
- loginPassword: "123456",
- sshPort: 9000,
- expected: []string{
- "# PermitRootLogin no",
- "PasswordAuthentication yes",
- "Port 9000",
- "PermitRootLogin yes",
- },
- },
- {
- config: []string{
- "# PermitRootLogin no",
- "PasswordAuthentication no",
- "Port 22",
- },
- loginAccount: "root",
- loginPassword: "123456",
- sshPort: 22,
- expected: []string{
- "# PermitRootLogin no",
- "PasswordAuthentication yes",
- "Port 22",
- "PermitRootLogin yes",
- },
- },
- {
- config: []string{
- "# PermitRootLogin no",
- "PasswordAuthentication no",
- "Port 22",
- },
- loginAccount: "root",
- loginPassword: "",
- sshPort: 22,
- expected: []string{
- "# PermitRootLogin no",
- "PasswordAuthentication no",
- "Port 22",
- "PermitRootLogin yes",
- },
- },
- }
- for _, c := range cases {
- actual := genSshdConfig(c.config, c.loginAccount, c.loginPassword, c.sshPort)
- if !reflect.DeepEqual(actual, c.expected) {
- t.Errorf("expected %v, got %v", c.expected, actual)
- }
- }
- }
|