Skip to content

Commit c3c3665

Browse files
Ramkishor ChaladiRamkishor Chaladi
authored andcommitted
Merge branch 'master' of github.ibm.com:SoftLayer/softlayer-cli into issue_719
testing
2 parents 8f347fe + f8b356f commit c3c3665

9 files changed

Lines changed: 191 additions & 2 deletions

File tree

plugin/commands/dedicatedhost/cancel_guest.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dedicatedhost
22

33
import (
44
"github.com/spf13/cobra"
5-
5+
66
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
77
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
88

@@ -61,6 +61,8 @@ func (cmd *CancelCommand) Run(args []string) error {
6161
if len(listGuest) > 0 {
6262
table := cmd.UI.Table([]string{T("Id"), T("Server Name"), T("Status")})
6363
for _, guest := range listGuest {
64+
//#nosec G601 -- utils.FormatXPointer returns the value of the memory address, so this is not a problem.
65+
//Test Issues787 assures this condition.
6466
table.Add(utils.FormatIntPointer(&guest.Id), utils.FormatStringPointer(&guest.Fqdn), utils.FormatStringPointer(&guest.Status))
6567
}
6668
table.Print()

plugin/commands/dedicatedhost/cancel_guest_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,28 @@ var _ = Describe("Dedicated host create", func() {
9191
})
9292
})
9393

94+
Context("Dedicatedhost VS cancel vs successfully - multiple", func() {
95+
BeforeEach(func() {
96+
FakeDedicatedhostManager.CancelGuestsReturns([]managers.StatusInfo{
97+
{
98+
Id: *sl.Int(1234567),
99+
Fqdn: *sl.String("test.softlayer"),
100+
Status: *sl.String("Cancelled"),
101+
},
102+
{
103+
Id: *sl.Int(9999),
104+
Fqdn: *sl.String("qqq.aaa"),
105+
Status: *sl.String("Cancelled"),
106+
},
107+
}, nil)
108+
})
109+
It("return no error", func() {
110+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "-f")
111+
Expect(err).NotTo(HaveOccurred())
112+
Expect(fakeUI.Outputs()).To(ContainSubstring("1234567"))
113+
Expect(fakeUI.Outputs()).To(ContainSubstring("9999"))
114+
})
115+
})
116+
94117
})
95118
})

plugin/commands/user/permissions.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,17 @@ func (cmd *PermissionsCommand) Run(args []string) error {
8484
}
8585

8686
}
87-
tablePermission.Add(utils.FormatStringPointer(perm.Name), utils.FormatStringPointer(perm.KeyName), strconv.FormatBool(assigned))
87+
flag := true
88+
arr := []string{"ACCOUNT_SUMMARY_VIEW", "REQUEST_COMPLIANCE_REPORT", "COMPANY_EDIT", "ONE_TIME_PAYMENTS", "UPDATE_PAYMENT_DETAILS",
89+
"EU_LIMITED_PROCESSING_MANAGE", "TICKET_ADD", "TICKET_EDIT", "TICKET_SEARCH", "TICKET_VIEW", "TICKET_VIEW_ALL"}
90+
for i := 0; i < len(arr); i++ {
91+
if *perm.KeyName == arr[i] {
92+
flag = false
93+
}
94+
}
95+
if flag == true {
96+
tablePermission.Add(utils.FormatStringPointer(perm.Name), utils.FormatStringPointer(perm.KeyName), strconv.FormatBool(assigned))
97+
}
8898
}
8999
tablePermission.Print()
90100
return nil

plugin/commands/user/permissions_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,24 @@ var _ = Describe("User Permissions", func() {
107107
})
108108
})
109109

110+
Context("hide user permissions", func() {
111+
It("return not equal user permissions", func() {
112+
err := testhelpers.RunCobraCommand(cliCommand.Command, "123")
113+
Expect(err).NotTo(HaveOccurred())
114+
Expect(fakeUI.Outputs()).NotTo(Equal("ACCOUNT_SUMMARY_VIEW"))
115+
Expect(fakeUI.Outputs()).To(Not(Equal("REQUEST_COMPLIANCE_REPORT")))
116+
Expect(fakeUI.Outputs()).To(Not(Equal("COMPANY_EDIT")))
117+
Expect(fakeUI.Outputs()).To(Not(Equal("ONE_TIME_PAYMENTS")))
118+
Expect(fakeUI.Outputs()).To(Not(Equal("UPDATE_PAYMENT_DETAILS")))
119+
Expect(fakeUI.Outputs()).To(Not(Equal("EU_LIMITED_PROCESSING_MANAGE")))
120+
Expect(fakeUI.Outputs()).To(Not(Equal("TICKET_ADD")))
121+
Expect(fakeUI.Outputs()).To(Not(Equal("TICKET_EDIT")))
122+
Expect(fakeUI.Outputs()).To(Not(Equal("TICKET_SEARCH")))
123+
Expect(fakeUI.Outputs()).To(Not(Equal("TICKET_VIEW")))
124+
Expect(fakeUI.Outputs()).To(Not(Equal("TICKET_VIEW_ALL")))
125+
})
126+
})
127+
110128
Context("user permissions - master account", func() {
111129
It("return user permissions", func() {
112130
fakeUserManager.GetUserReturns(datatypes.User_Customer{

plugin/commands/user/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func SetupCobraCommands(sl *metadata.SoftlayerCommand) *cobra.Command {
2929
cobraCmd.AddCommand(NewVpnSubnetCommand(sl).Command)
3030
cobraCmd.AddCommand(NewVpnManualCommand(sl).Command)
3131
cobraCmd.AddCommand(NewVpnPasswordCommand(sl).Command)
32+
cobraCmd.AddCommand(NewVpnDisableCommand(sl).Command)
3233
cobraCmd.AddCommand(NewVpnEnableCommand(sl).Command)
3334
cobraCmd.AddCommand(NewApikeyCommand(sl).Command)
3435
return cobraCmd

plugin/commands/user/user_suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var availableCommands = []string{
3535
"vpn-manual",
3636
"vpn-password",
3737
"vpn-subnet",
38+
"vpn-disable",
3839
"vpn-enable",
3940
}
4041

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package user
2+
3+
import (
4+
"strconv"
5+
6+
"github.com/softlayer/softlayer-go/datatypes"
7+
"github.com/softlayer/softlayer-go/sl"
8+
"github.com/spf13/cobra"
9+
10+
slErrors "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
11+
. "github.ibm.com/SoftLayer/softlayer-cli/plugin/i18n"
12+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/managers"
13+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
14+
)
15+
16+
type VpnDisableCommand struct {
17+
*metadata.SoftlayerCommand
18+
UserManager managers.UserManager
19+
Command *cobra.Command
20+
}
21+
22+
func NewVpnDisableCommand(sl *metadata.SoftlayerCommand) (cmd *VpnDisableCommand) {
23+
thisCmd := &VpnDisableCommand{
24+
SoftlayerCommand: sl,
25+
UserManager: managers.NewUserManager(sl.Session),
26+
}
27+
28+
cobraCmd := &cobra.Command{
29+
Use: "vpn-disable " + T("USER_ID"),
30+
Short: T("Disable vpn for a user."),
31+
Args: metadata.OneArgs,
32+
RunE: func(cmd *cobra.Command, args []string) error {
33+
return thisCmd.Run(args)
34+
},
35+
}
36+
37+
thisCmd.Command = cobraCmd
38+
return thisCmd
39+
}
40+
41+
func (cmd *VpnDisableCommand) Run(args []string) error {
42+
userID, err := strconv.Atoi(args[0])
43+
if err != nil {
44+
return slErrors.NewInvalidSoftlayerIdInputError("User ID")
45+
}
46+
userTemplate := datatypes.User_Customer{
47+
SslVpnAllowedFlag: sl.Bool(false),
48+
}
49+
success, err := cmd.UserManager.EditUser(userTemplate, userID)
50+
if err != nil {
51+
return slErrors.NewAPIError(T(""), err.Error(), 2)
52+
}
53+
if success {
54+
cmd.UI.Ok()
55+
}
56+
return nil
57+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package user_test
2+
3+
import (
4+
"errors"
5+
6+
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
7+
. "github.com/onsi/ginkgo"
8+
. "github.com/onsi/gomega"
9+
"github.com/softlayer/softlayer-go/datatypes"
10+
"github.com/softlayer/softlayer-go/session"
11+
"github.com/softlayer/softlayer-go/sl"
12+
13+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/user"
14+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
15+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
16+
)
17+
18+
var _ = Describe("user vpn-enable", func() {
19+
var (
20+
fakeUI *terminal.FakeUI
21+
cliCommand *user.VpnDisableCommand
22+
fakeSession *session.Session
23+
slCommand *metadata.SoftlayerCommand
24+
fakeUserManager *testhelpers.FakeUserManager
25+
)
26+
BeforeEach(func() {
27+
fakeUI = terminal.NewFakeUI()
28+
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{})
29+
fakeUserManager = new(testhelpers.FakeUserManager)
30+
slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession)
31+
cliCommand = user.NewVpnDisableCommand(slCommand)
32+
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
33+
cliCommand.UserManager = fakeUserManager
34+
35+
testUser = datatypes.User_Customer{
36+
SslVpnAllowedFlag: sl.Bool(false),
37+
}
38+
})
39+
40+
Describe("user vpn-enable", func() {
41+
42+
Context("Return error", func() {
43+
It("Set command without Argument", func() {
44+
err := testhelpers.RunCobraCommand(cliCommand.Command)
45+
Expect(err).To(HaveOccurred())
46+
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument."))
47+
})
48+
49+
It("Set command with an invalid user Id", func() {
50+
err := testhelpers.RunCobraCommand(cliCommand.Command, "abcde")
51+
Expect(err).To(HaveOccurred())
52+
Expect(err.Error()).To(ContainSubstring("Invalid input for 'User ID'. It must be a positive integer."))
53+
})
54+
})
55+
56+
Context("Account cancel-item, softlayer errors", func() {
57+
It("Set command with unknow item ID", func() {
58+
fakeUserManager.EditUserReturns(true, errors.New("SoftLayer_Exception_ObjectNotFound: Unable to find object with id of '123'. (HTTP 404)"))
59+
err := testhelpers.RunCobraCommand(cliCommand.Command, "123")
60+
Expect(err).To(HaveOccurred())
61+
Expect(err.Error()).To(ContainSubstring("SoftLayer_Exception_ObjectNotFound: Unable to find object with id of '123'. (HTTP 404)"))
62+
})
63+
})
64+
65+
Context("Return no error", func() {
66+
BeforeEach(func() {
67+
fakeUserManager.EditUserReturns(true, nil)
68+
})
69+
It("enable", func() {
70+
err := testhelpers.RunCobraCommand(cliCommand.Command, "111111")
71+
Expect(err).NotTo(HaveOccurred())
72+
Expect(fakeUI.Outputs()).To(ContainSubstring("OK"))
73+
})
74+
})
75+
})
76+
})

plugin/managers/network.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ func (n networkManager) AddSubnet(subnetType string, quantity int, vlanID int, v
220220
quantity = 0
221221
category = "global_ipv4"
222222
} else if subnetType == "public" {
223+
//#nosec G101 -- Not a credential
223224
category = "sov_sec_ip_addresses_pub"
224225
}
225226
} else {

0 commit comments

Comments
 (0)