Skip to content

Commit c932956

Browse files
committed
Bug bash feedback
1 parent 84c3708 commit c932956

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1295
-622
lines changed

SECURITY.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
66

7-
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below.
7+
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below.
88

99
## Reporting Security Issues
1010

1111
**Please do not report security vulnerabilities through public GitHub issues.**
1212

1313
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
1414

15-
If you prefer to submit without logging in, send email to [[email protected]](mailto:[email protected]). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
15+
If you prefer to submit without logging in, send email to [[email protected]](mailto:[email protected]). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/msrc/pgp-key-msrc).
1616

1717
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
1818

@@ -36,6 +36,6 @@ We prefer all communications to be in English.
3636

3737
## Policy
3838

39-
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
39+
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/msrc/cvd).
4040

4141
<!-- END MICROSOFT SECURITY.MD BLOCK -->

cmd/modern/main_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ func TestDisplayHints(t *testing.T) {
3737
}
3838

3939
func TestCheckErr(t *testing.T) {
40+
rootCmd = cmdparser.New[*Root](dependency.Options{})
41+
rootCmd.loggingLevel = 4
42+
checkErr(nil)
4043
assert.Panics(t, func() {
41-
rootCmd = cmdparser.New[*Root](dependency.Options{})
42-
rootCmd.loggingLevel = 4
43-
checkErr(nil)
4444
checkErr(errors.New("test error"))
4545
})
4646
}

cmd/modern/root.go

+22-10
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@ func (c *Root) DefineCommand(...cmdparser.CommandOptions) {
2828
// Example usage steps
2929
steps := []string{"sqlcmd create mssql --accept-eula --using https://aka.ms/AdventureWorksLT.bak"}
3030

31-
if runtime.GOOS == "windows" {
31+
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
3232
steps = append(steps, "sqlcmd open ads")
3333
}
3434

3535
steps = append(steps, `sqlcmd query "SELECT @@version"`)
3636
steps = append(steps, "sqlcmd delete")
3737

38-
examples := []cmdparser.ExampleOptions{{
39-
Description: "Install/Create, Query, Uninstall SQL Server",
40-
Steps: steps}}
38+
examples := []cmdparser.ExampleOptions{
39+
{Description: "Install/Create, Query, Uninstall SQL Server",
40+
Steps: steps},
41+
{Description: "View configuration information and connection strings",
42+
Steps: []string{"sqlcmd config view", "sqlcmd config cs"}},
43+
}
4144

4245
commandOptions := cmdparser.CommandOptions{
4346
Use: "sqlcmd",
@@ -67,8 +70,8 @@ func (c *Root) SubCommands() []cmdparser.Command {
6770
cmdparser.New[*root.Uninstall](dependencies),
6871
}
6972

70-
// BUG:(stuartpa) - Add Mac / Linux support
71-
if runtime.GOOS == "windows" {
73+
// BUG(stuartpa): - Add Linux support
74+
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
7275
subCommands = append(subCommands, cmdparser.New[*root.Open](dependencies))
7376
}
7477

@@ -91,7 +94,7 @@ func (c *Root) IsValidSubCommand(command string) bool {
9194

9295
func (c *Root) addGlobalFlags() {
9396

94-
// BUG:(stuartpa) - This is a temporary flag until we have migrated
97+
// BUG(stuartpa): - This is a temporary flag until we have migrated
9598
// the kong impl to cobra. sqlcmd -? will show the kong help (all the back-compat
9699
// flags), sqlcmd --? will show the kong "did you mean one of" help.
97100
var unused bool
@@ -102,14 +105,23 @@ func (c *Root) addGlobalFlags() {
102105
Usage: "help for backwards compatibility flags (-S, -U, -E etc.)",
103106
})
104107

108+
// BUG(stuartpa): - This is a temporary flag until we have migrated
109+
// the kong impl to cobra. The implementation of --version is coming from
110+
// kong, but we need to add it to the list of flags so that it shows up in the --help
111+
c.AddFlag(cmdparser.FlagOptions{
112+
Bool: &unused,
113+
Name: "version",
114+
Usage: "print version of sqlcmd",
115+
})
116+
105117
c.AddFlag(cmdparser.FlagOptions{
106118
String: &c.configFilename,
107119
DefaultString: config.DefaultFileName(),
108120
Name: "sqlconfig",
109-
Usage: "Configuration file",
121+
Usage: "configuration file",
110122
})
111123

112-
/* BUG:(stuartpa) - At the moment this is a top level flag, but it doesn't
124+
/* BUG(stuartpa): - At the moment this is a top level flag, but it doesn't
113125
work with all sub-commands (e.g. query), so removing for now.
114126
c.AddFlag(cmdparser.FlagOptions{
115127
String: &c.outputType,
@@ -124,6 +136,6 @@ func (c *Root) addGlobalFlags() {
124136
Int: (*int)(&c.loggingLevel),
125137
DefaultInt: 2,
126138
Name: "verbosity",
127-
Usage: "Log level, error=0, warn=1, info=2, debug=3, trace=4",
139+
Usage: "log level, error=0, warn=1, info=2, debug=3, trace=4",
128140
})
129141
}

cmd/modern/root/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ func (c *Config) DefineCommand(...cmdparser.CommandOptions) {
2424
SubCommands: c.SubCommands(),
2525
Examples: []cmdparser.ExampleOptions{
2626
{
27-
Description: "Add context for existing endpoint and user",
27+
Description: "Add context for existing endpoint and user (use SQLCMD_PASSWORD or SQLCMDPASSWORD)",
2828
Steps: []string{
29-
fmt.Sprintf("%s SQLCMD_PASSWORD=<password>", pal.CreateEnvVarKeyword()),
29+
fmt.Sprintf("%s SQLCMD_PASSWORD=<placeholderpassword>", pal.CreateEnvVarKeyword()),
3030
"sqlcmd config add-user --name sa1434 --username sa",
3131
fmt.Sprintf("%s SQLCMD_PASSWORD=", pal.CreateEnvVarKeyword()),
3232
"sqlcmd config add-endpoint --name ep1434 --address localhost --port 1434",

cmd/modern/root/config/add-context_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ func TestAddContext(t *testing.T) {
1616
}
1717

1818
func TestNegAddContext(t *testing.T) {
19+
cmdparser.TestSetup(t)
1920
assert.Panics(t, func() {
20-
cmdparser.TestSetup(t)
2121
cmdparser.TestCmd[*AddContext]("--endpoint does-not-exist")
2222
})
2323
}
2424

2525
func TestNegAddContext2(t *testing.T) {
26+
cmdparser.TestSetup(t)
27+
cmdparser.TestCmd[*AddEndpoint]()
2628
assert.Panics(t, func() {
27-
cmdparser.TestSetup(t)
28-
cmdparser.TestCmd[*AddEndpoint]()
2929
cmdparser.TestCmd[*AddContext]("--endpoint endpoint --user does-not-exist")
3030
})
3131
}

cmd/modern/root/config/add-user.go

+27-8
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,21 @@ func (c *AddUser) DefineCommand(...cmdparser.CommandOptions) {
3030
Short: "Add a user",
3131
Examples: []cmdparser.ExampleOptions{
3232
{
33-
Description: "Add a user",
33+
Description: "Add a user (using the SQLCMD_PASSWORD environment variable)",
3434
Steps: []string{
35-
fmt.Sprintf(`%s SQLCMD_PASSWORD=<password>`, pal.CreateEnvVarKeyword()),
35+
fmt.Sprintf(`%s SQLCMD_PASSWORD=<placeholderpassword>`, pal.CreateEnvVarKeyword()),
3636
"sqlcmd config add-user --name my-user --username user1",
3737
fmt.Sprintf(`%s SQLCMD_PASSWORD=`, pal.CreateEnvVarKeyword()),
3838
},
3939
},
40+
{
41+
Description: "Add a user (using the SQLCMDPASSWORD environment variable)",
42+
Steps: []string{
43+
fmt.Sprintf(`%s SQLCMDPASSWORD=<placeholderpassword>`, pal.CreateEnvVarKeyword()),
44+
"sqlcmd config add-user --name my-user --username user1",
45+
fmt.Sprintf(`%s SQLCMDPASSWORD=`, pal.CreateEnvVarKeyword()),
46+
},
47+
},
4048
},
4149
Run: c.run}
4250

@@ -59,7 +67,7 @@ func (c *AddUser) DefineCommand(...cmdparser.CommandOptions) {
5967
c.AddFlag(cmdparser.FlagOptions{
6068
String: &c.username,
6169
Name: "username",
62-
Usage: "The username (provide password in SQLCMD_PASSWORD environment variable)",
70+
Usage: "The username (provide password in SQLCMD_PASSWORD or SQLCMDPASSWORD environment variable)",
6371
})
6472

6573
c.encryptPasswordFlag()
@@ -95,24 +103,35 @@ func (c *AddUser) run() {
95103
}
96104

97105
if c.authType == "basic" {
98-
if os.Getenv("SQLCMD_PASSWORD") == "" {
106+
if os.Getenv("SQLCMD_PASSWORD") == "" && os.Getenv("SQLCMDPASSWORD") == "" {
99107
output.FatalWithHints([]string{
100-
"Provide password in the SQLCMD_PASSWORD environment variable"},
108+
"Provide password in the SQLCMD_PASSWORD (or SQLCMDPASSWORD) environment variable"},
101109
"Authentication Type 'basic' requires a password")
102110
}
103111

104112
if c.username == "" {
105113
output.FatalfWithHintExamples([][]string{
106114
{"Provide a username with the --username flag",
107-
"sqlcmd config add-user --username stuartpa"},
115+
"sqlcmd config add-user --username sa"},
108116
},
109-
"Username not provider")
117+
"Username not provided")
110118
}
111119

120+
if os.Getenv("SQLCMD_PASSWORD") != "" &&
121+
os.Getenv("SQLCMDPASSWORD") != "" {
122+
output.FatalWithHints([]string{
123+
"Unset one of the environment variables SQLCMD_PASSWORD or SQLCMDPASSWORD"},
124+
"Both environment variables SQLCMD_PASSWORD and SQLCMDPASSWORD are set. ")
125+
}
126+
127+
password := os.Getenv("SQLCMD_PASSWORD")
128+
if password == "" {
129+
password = os.Getenv("SQLCMDPASSWORD")
130+
}
112131
user.BasicAuth = &sqlconfig.BasicAuthDetails{
113132
Username: c.username,
114133
PasswordEncrypted: c.encryptPassword,
115-
Password: secret.Encode(os.Getenv("SQLCMD_PASSWORD"), c.encryptPassword),
134+
Password: secret.Encode(password, c.encryptPassword),
116135
}
117136
}
118137

cmd/modern/root/config/add-user_test.go

+26-11
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,57 @@ import (
1010
"testing"
1111
)
1212

13+
// TestAddUser tests that the `sqlcmd config add-user` command
14+
// works as expected
1315
func TestAddUser(t *testing.T) {
14-
os.Setenv("SQLCMD_PASSWORD", "it's-a-secret")
16+
17+
// SQLCMDPASSWORD is already set in the build pipelines, so don't
18+
// overwrite it here.
19+
if os.Getenv("SQLCMDPASSWORD") == "" {
20+
os.Setenv("SQLCMDPASSWORD", "it's-a-secret")
21+
}
1522
cmdparser.TestSetup(t)
1623
cmdparser.TestCmd[*AddUser]("--username user1")
1724
}
1825

26+
// TestNegAddUser tests that the `sqlcmd config add-user` command
27+
// fails when the auth-type is invalid
1928
func TestNegAddUser(t *testing.T) {
29+
cmdparser.TestSetup(t)
2030
assert.Panics(t, func() {
21-
cmdparser.TestSetup(t)
2231
cmdparser.TestCmd[*AddUser]("--username user1 --auth-type bad-bad")
2332
})
2433
}
2534

35+
// TestNegAddUser2 tests that the `sqlcmd config add-user` command
36+
// fails when the auth-type is not basic and --encrypt-password is set
2637
func TestNegAddUser2(t *testing.T) {
38+
cmdparser.TestSetup(t)
2739
assert.Panics(t, func() {
28-
cmdparser.TestSetup(t)
2940
cmdparser.TestCmd[*AddUser]("--username user1 --auth-type other --encrypt-password")
3041
})
3142
}
3243

44+
// TestNegAddUser3 tests that the `sqlcmd config add-user` command
45+
// fails when the SQLCMD_PASSWORD environment variable is not set
3346
func TestNegAddUser3(t *testing.T) {
34-
assert.Panics(t, func() {
35-
36-
os.Setenv("SQLCMD_PASSWORD", "")
47+
if os.Getenv("SQLCMDPASSWORD") != "" {
48+
os.Setenv("SQLCMDPASSWORD", "")
49+
}
3750

38-
cmdparser.TestSetup(t)
51+
cmdparser.TestSetup(t)
52+
assert.Panics(t, func() {
3953
cmdparser.TestCmd[*AddUser]("--username user1")
4054
})
4155
}
4256

57+
// TestNegAddUser4 tests that the `sqlcmd config add-user` command
58+
// when username is not set
4359
func TestNegAddUser4(t *testing.T) {
44-
assert.Panics(t, func() {
45-
46-
os.Setenv("SQLCMD_PASSWORD", "whatever")
60+
os.Setenv("SQLCMD_PASSWORD", "whatever")
4761

48-
cmdparser.TestSetup(t)
62+
cmdparser.TestSetup(t)
63+
assert.Panics(t, func() {
4964
cmdparser.TestCmd[*AddUser]()
5065
})
5166
}

0 commit comments

Comments
 (0)