Skip to content

Commit

Permalink
Some changes from "go fmt", mostly whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindhagberg committed Sep 16, 2022
1 parent e37b2f4 commit ab94403
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion server/service/api_grep.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ outer:

// Possibly filter out hosts with undetermined hostnames
if config.HideUnknownHosts {
if _,ok := certfp2hostname[certfp]; !ok {
if _, ok := certfp2hostname[certfp]; !ok {
continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/service/api_hostlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (vars *apiMethodHostList) ServeGET(w http.ResponseWriter, req *http.Request
temp := make([]string, 0, len(apiHostListStandardFields))
for _, f := range apiHostListStandardFields {
if f.expression != "" {
temp = append(temp, f.expression + " AS " + f.columnName)
temp = append(temp, f.expression+" AS "+f.columnName)
} else {
temp = append(temp, f.columnName)
}
Expand Down
34 changes: 17 additions & 17 deletions server/service/api_hostlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ func TestApiMethodHostList(t *testing.T) {
},
// Regression tests for a bug (See GitHub issue #151)
{
methodAndPath: "GET /api/v2/hostlist?fields=hostname,os,duck&ipAddress=129.240.98.*",
expectStatus: http.StatusOK,
methodAndPath: "GET /api/v2/hostlist?fields=hostname,os,duck&ipAddress=129.240.98.*",
expectStatus: http.StatusOK,
},
{
methodAndPath: "GET /api/v2/hostlist?fields=hostname,os&ipAddress=129.240.98.*",
expectStatus: http.StatusOK,
methodAndPath: "GET /api/v2/hostlist?fields=hostname,os&ipAddress=129.240.98.*",
expectStatus: http.StatusOK,
},
}

Expand Down Expand Up @@ -281,32 +281,32 @@ func TestApiMethodHostList(t *testing.T) {
}

func TestHideUnknownHosts(t *testing.T) {
if os.Getenv("NOPOSTGRES") != "" {
t.Log("No Postgres, skipping test")
return
}
if os.Getenv("NOPOSTGRES") != "" {
t.Log("No Postgres, skipping test")
return
}

db := getDBconnForTesting(t)
defer db.Close()
_, err := db.Exec("INSERT INTO hostinfo(certfp,hostname,ipaddr,os_edition) VALUES" +
"('1111','foo.bar.no','1.1.1.1','workstation')," +
"('2222',null,'2.2.2.2','workstation')")
if err != nil {
t.Error(err)
}
defer db.Close()
_, err := db.Exec("INSERT INTO hostinfo(certfp,hostname,ipaddr,os_edition) VALUES" +
"('1111','foo.bar.no','1.1.1.1','workstation')," +
"('2222',null,'2.2.2.2','workstation')")
if err != nil {
t.Error(err)
}

testsWhenOptionOff := []apiCall{
{
methodAndPath: "GET /api/v2/hostlist?fields=hostname",
expectStatus: http.StatusOK,
expectJSON: `[{"hostname":"2.2.2.2"},{"hostname":"foo.bar.no"}]`,
expectJSON: `[{"hostname":"2.2.2.2"},{"hostname":"foo.bar.no"}]`,
},
}
testsWhenOptionOn := []apiCall{
{
methodAndPath: "GET /api/v2/hostlist?fields=hostname",
expectStatus: http.StatusOK,
expectJSON: `[{"hostname":"foo.bar.no"}]`,
expectJSON: `[{"hostname":"foo.bar.no"}]`,
},
}

Expand Down
24 changes: 12 additions & 12 deletions server/service/api_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,37 +113,37 @@ func TestSearchCaseSensitivity(t *testing.T) {
// Test a search that returns ip address and hostname
{
methodAndPath: "GET /api/v2/search?q=night&fields=ipAddress,hostname",
expectStatus: http.StatusOK,
expectJSON: `[{"ipAddress":"` + ip2 + `","hostname":"`+hostname2+`"}]`,
expectStatus: http.StatusOK,
expectJSON: `[{"ipAddress":"` + ip2 + `","hostname":"` + hostname2 + `"}]`,
},
{
methodAndPath: "GET /api/v2/msearch?q1=night&fields=ipAddress,hostname",
expectStatus: http.StatusOK,
expectJSON: `[{"ipAddress":"` + ip2 + `","hostname":"`+hostname2+`"}]`,
expectStatus: http.StatusOK,
expectJSON: `[{"ipAddress":"` + ip2 + `","hostname":"` + hostname2 + `"}]`,
},
// A search that returns two hosts
{
methodAndPath: "GET /api/v2/search?q=sugar&fields=hostname",
expectStatus: http.StatusOK,
expectJSON: `[{"hostname":"`+hostname2+`"},{"hostname":"`+hostname+`"}]`,
expectStatus: http.StatusOK,
expectJSON: `[{"hostname":"` + hostname2 + `"},{"hostname":"` + hostname + `"}]`,
},
{
methodAndPath: "GET /api/v2/msearch?q1=sugar&fields=hostname",
expectStatus: http.StatusOK,
expectJSON: `[{"hostname":"`+hostname+`"},{"hostname":"`+hostname2+`"}]`,
expectStatus: http.StatusOK,
expectJSON: `[{"hostname":"` + hostname + `"},{"hostname":"` + hostname2 + `"}]`,
},
{
methodAndPath: "GET /api/v2/grep?q=sugar",
expectStatus: http.StatusOK,
expectContent: hostname2+":"+filename+":"+content2+"\n"+hostname+":"+filename+":"+content,
expectStatus: http.StatusOK,
expectContent: hostname2 + ":" + filename + ":" + content2 + "\n" + hostname + ":" + filename + ":" + content,
},
}

// Run the tests
testAPIcalls(t, api, tests)

// Also run the tests with option HideUnknownHosts=true
config.HideUnknownHosts=true
config.HideUnknownHosts = true
// Add a host without a name, that shouldn't show up in the results
certfp3 := "CCCCCC"
_, err = db.Exec("INSERT INTO files(fileid,filename,certfp,content,ipaddr) "+
Expand All @@ -159,5 +159,5 @@ func TestSearchCaseSensitivity(t *testing.T) {
}
addFileToFastSearch(fileID+2, certfp3, filename, content)
testAPIcalls(t, api, tests)
config.HideUnknownHosts=false
config.HideUnknownHosts = false
}
2 changes: 1 addition & 1 deletion server/service/api_searchpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (vars *apiMethodSearchPage) ServeHTTP(w http.ResponseWriter, req *http.Requ
statement := "SELECT certfp FROM hostinfo"
whereAnd := "WHERE"
if !access.HasAccessToAllGroups() {
statement += " " + whereAnd + " ownergroup IN ("+access.GetGroupListForSQLWHERE()+")"
statement += " " + whereAnd + " ownergroup IN (" + access.GetGroupListForSQLWHERE() + ")"
whereAnd = "AND"
}
if config.HideUnknownHosts {
Expand Down
2 changes: 1 addition & 1 deletion server/service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func updateConfig(config *Config, key string, value string) {
// Options in the file must have the same name as fields in the struct,
// disregarding upper/lowercase.
// Options with names that aren't recognized are ignored.
func UpdateConfigFromFile(config *Config, configFileName string) (error) {
func UpdateConfigFromFile(config *Config, configFileName string) error {
// Open the config file
file, err := os.Open(configFileName)
if err != nil {
Expand Down

0 comments on commit ab94403

Please sign in to comment.