Skip to content
Snippets Groups Projects
Commit c7f0177b authored by ale's avatar ale
Browse files

Cleanup the 'webappdb' test

parent 902b949c
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,10 @@ inspected by pre-defined aggregations (*queries*), that are shipped ...@@ -55,6 +55,10 @@ inspected by pre-defined aggregations (*queries*), that are shipped
with the server configuration and can be queried via the RPC with the server configuration and can be queried via the RPC
interface, which can take advantage of the SQLITE JSON extensions. interface, which can take advantage of the SQLITE JSON extensions.
The *application-specific key* is a separate and independent key space
hooked off the primary (shard / type / resource_id) key, which allows
one to store multiple entries for the same type and resource.
Q: Isn't this just a way to achieve SQL sharding? Q: Isn't this just a way to achieve SQL sharding?
A: In a sense, yes, but with RPC APIs tuned to a very specific use A: In a sense, yes, but with RPC APIs tuned to a very specific use
......
...@@ -26,11 +26,11 @@ var ( ...@@ -26,11 +26,11 @@ var (
Results: []QueryParam{ Results: []QueryParam{
{ {
Name: "resource_id", Name: "resource_id",
Type: "string", Type: TypeString,
}, },
{ {
Name: "usage", Name: "usage",
Type: "int", Type: TypeInt,
}, },
}, },
} }
...@@ -39,11 +39,11 @@ var ( ...@@ -39,11 +39,11 @@ var (
Results: []QueryParam{ Results: []QueryParam{
{ {
Name: "timestamp", Name: "timestamp",
Type: "timestamp", Type: TypeTimestamp,
}, },
{ {
Name: "usage", Name: "usage",
Type: "int", Type: TypeInt,
}, },
}, },
} }
......
...@@ -13,25 +13,25 @@ var ( ...@@ -13,25 +13,25 @@ var (
SELECT SELECT
resource_id, resource_id,
app_key, app_key,
json_extract(value_json, '$.name') as name, json_extract(value_json, '$.appname') as appname,
json_extract(value_json, '$.version') as version, json_extract(value_json, '$.version') as version,
json_extract(value_json, '$.safe_version') as version, json_extract(value_json, '$.safeversion') as safeversion,
json_extract(value_json, '$.state') as state, json_extract(value_json, '$.state') as state,
json_extract(value_json, '$.vulninfo') as vulninfo json_extract(value_json, '$.vulninfo') as vulninfo
FROM FROM
latest latest
WHERE WHERE
type = 'webapp' AND type = 'webapp' AND
name = :app appname = :app
`, `,
Results: []QueryParam{ Results: []QueryParam{
{Name: "resource_id", Type: "string"}, {Name: "resource_id", Type: TypeString},
{Name: "app_key", Type: "string"}, {Name: "app_key", Type: TypeString},
{Name: "name", Type: "string"}, {Name: "appname", Type: TypeString},
{Name: "version", Type: "string"}, {Name: "version", Type: TypeString},
{Name: "safe_version", Type: "string"}, {Name: "safeversion", Type: TypeString},
{Name: "state", Type: "string"}, {Name: "state", Type: TypeString},
{Name: "vulninfo", Type: "string"}, {Name: "vulninfo", Type: TypeString},
}, },
} }
...@@ -39,18 +39,18 @@ WHERE ...@@ -39,18 +39,18 @@ WHERE
SQL: ` SQL: `
SELECT SELECT
COUNT(*) AS c, COUNT(*) AS c,
json_extract(value_json, '$.name') as name, json_extract(value_json, '$.appname') as appname,
json_extract(value_json, '$.version') as version json_extract(value_json, '$.version') as version
FROM latest FROM latest
WHERE WHERE
type = 'webapp' type = 'webapp'
AND name = :app AND appname = :app
ORDER BY c DESC ORDER BY c DESC
`, `,
Results: []QueryParam{ Results: []QueryParam{
{Name: "count", Type: "int"}, {Name: "count", Type: TypeInt},
{Name: "name", Type: "string"}, {Name: "appname", Type: TypeString},
{Name: "version", Type: "string"}, {Name: "version", Type: TypeString},
}, },
} }
) )
...@@ -63,24 +63,23 @@ func (c *testCtx) loadWebappTestData(t testing.TB) { ...@@ -63,24 +63,23 @@ func (c *testCtx) loadWebappTestData(t testing.TB) {
Entries: []auxpb.LoadEntry{ Entries: []auxpb.LoadEntry{
{ {
ResourceID: "website1", ResourceID: "website1",
AppKey: "path/1", AppKey: "/path/1",
ValueJSON: ` ValueJSON: `
{"name": "Wordpress", "version": "4.5.1", "safe_version": "5.6", {"appname": "Wordpress", "version": "4.5.1", "safeversion": "5.6",
"state": "vulnerable", "vulninfo": "FOO BAR PHP SHELL"}`, "state": "vulnerable", "vulninfo": "CVE-2019-17672"}`,
}, },
{ {
ResourceID: "website1", ResourceID: "website1",
AppKey: "path/2", AppKey: "/path/2",
ValueJSON: ` ValueJSON: `
{"name": "Wordpress-plugin", "version": "0.1", "safe_version": "0.2", {"appname": "Wordpress-plugin", "version": "0.1", "state": "ok"}`,
"state": "vulnerable", "vulninfo": "FOO BAR PHP SHELL"}`,
}, },
{ {
ResourceID: "website2", ResourceID: "website2",
AppKey: "path/3", AppKey: "/path/3",
ValueJSON: ` ValueJSON: `
{"name": "Wordpress", "version": "4.5.1", "safe_version": "5.6", {"appname": "Wordpress", "version": "4.5.1", "safeversion": "5.6",
"state": "vulnerable", "vulninfo": "FOO BAR PHP SHELL"}`, "state": "vulnerable", "vulninfo": "CVE-2019-17672"}`,
}, },
}, },
}, nil) }, nil)
...@@ -113,6 +112,11 @@ func TestWebapp_Get(t *testing.T) { ...@@ -113,6 +112,11 @@ func TestWebapp_Get(t *testing.T) {
if len(resp.Results) != 2 { if len(resp.Results) != 2 {
t.Fatalf("expected 2 results, got %d: %v", len(resp.Results), resp.Results) t.Fatalf("expected 2 results, got %d: %v", len(resp.Results), resp.Results)
} }
for _, entry := range resp.Results {
if entry.Key.AppKey != "/path/1" && entry.Key.AppKey != "/path/2" {
t.Errorf("invalid app_key in result: %s", entry.Key.AppKey)
}
}
} }
func TestWebapp_Query_Find(t *testing.T) { func TestWebapp_Query_Find(t *testing.T) {
...@@ -137,6 +141,12 @@ func TestWebapp_Query_Find(t *testing.T) { ...@@ -137,6 +141,12 @@ func TestWebapp_Query_Find(t *testing.T) {
if resp.Results[0][3].(string) != "4.5.1" { if resp.Results[0][3].(string) != "4.5.1" {
t.Fatalf("bad result: %v", resp.Results[0]) t.Fatalf("bad result: %v", resp.Results[0])
} }
for _, r := range resp.Results {
appKey := r[1].(string)
if appKey != "/path/1" && appKey != "/path/3" {
t.Errorf("invalid app_key in result: %s", appKey)
}
}
} }
func TestWebapp_Query_Count(t *testing.T) { func TestWebapp_Query_Count(t *testing.T) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment