Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aux-db
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai3
tools
aux-db
Commits
c7f0177b
Commit
c7f0177b
authored
4 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup the 'webappdb' test
parent
902b949c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+4
-0
4 additions, 0 deletions
README.md
server_test.go
+4
-4
4 additions, 4 deletions
server_test.go
server_webappdb_test.go
+34
-24
34 additions, 24 deletions
server_webappdb_test.go
with
42 additions
and
28 deletions
README.md
+
4
−
0
View file @
c7f0177b
...
...
@@ -55,6 +55,10 @@ inspected by pre-defined aggregations (*queries*), that are shipped
with the server configuration and can be queried via the RPC
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?
A: In a sense, yes, but with RPC APIs tuned to a very specific use
...
...
This diff is collapsed.
Click to expand it.
server_test.go
+
4
−
4
View file @
c7f0177b
...
...
@@ -26,11 +26,11 @@ var (
Results
:
[]
QueryParam
{
{
Name
:
"resource_id"
,
Type
:
"s
tring
"
,
Type
:
TypeS
tring
,
},
{
Name
:
"usage"
,
Type
:
"i
nt
"
,
Type
:
TypeI
nt
,
},
},
}
...
...
@@ -39,11 +39,11 @@ var (
Results
:
[]
QueryParam
{
{
Name
:
"timestamp"
,
Type
:
"t
imestamp
"
,
Type
:
TypeT
imestamp
,
},
{
Name
:
"usage"
,
Type
:
"i
nt
"
,
Type
:
TypeI
nt
,
},
},
}
...
...
This diff is collapsed.
Click to expand it.
server_webappdb_test.go
+
34
−
24
View file @
c7f0177b
...
...
@@ -13,25 +13,25 @@ var (
SELECT
resource_id,
app_key,
json_extract(value_json, '$.name') as name,
json_extract(value_json, '$.
app
name') as
app
name,
json_extract(value_json, '$.version') as version,
json_extract(value_json, '$.safe
_
version') as version,
json_extract(value_json, '$.safeversion') as
safe
version,
json_extract(value_json, '$.state') as state,
json_extract(value_json, '$.vulninfo') as vulninfo
FROM
latest
WHERE
type = 'webapp' AND
name = :app
app
name = :app
`
,
Results
:
[]
QueryParam
{
{
Name
:
"resource_id"
,
Type
:
"s
tring
"
},
{
Name
:
"app_key"
,
Type
:
"s
tring
"
},
{
Name
:
"name"
,
Type
:
"s
tring
"
},
{
Name
:
"version"
,
Type
:
"s
tring
"
},
{
Name
:
"safe
_
version"
,
Type
:
"s
tring
"
},
{
Name
:
"state"
,
Type
:
"s
tring
"
},
{
Name
:
"vulninfo"
,
Type
:
"s
tring
"
},
{
Name
:
"resource_id"
,
Type
:
TypeS
tring
},
{
Name
:
"app_key"
,
Type
:
TypeS
tring
},
{
Name
:
"
app
name"
,
Type
:
TypeS
tring
},
{
Name
:
"version"
,
Type
:
TypeS
tring
},
{
Name
:
"safeversion"
,
Type
:
TypeS
tring
},
{
Name
:
"state"
,
Type
:
TypeS
tring
},
{
Name
:
"vulninfo"
,
Type
:
TypeS
tring
},
},
}
...
...
@@ -39,18 +39,18 @@ WHERE
SQL
:
`
SELECT
COUNT(*) AS c,
json_extract(value_json, '$.name') as name,
json_extract(value_json, '$.
app
name') as
app
name,
json_extract(value_json, '$.version') as version
FROM latest
WHERE
type = 'webapp'
AND name = :app
AND
app
name = :app
ORDER BY c DESC
`
,
Results
:
[]
QueryParam
{
{
Name
:
"count"
,
Type
:
"i
nt
"
},
{
Name
:
"name"
,
Type
:
"s
tring
"
},
{
Name
:
"version"
,
Type
:
"s
tring
"
},
{
Name
:
"count"
,
Type
:
TypeI
nt
},
{
Name
:
"
app
name"
,
Type
:
TypeS
tring
},
{
Name
:
"version"
,
Type
:
TypeS
tring
},
},
}
)
...
...
@@ -63,24 +63,23 @@ func (c *testCtx) loadWebappTestData(t testing.TB) {
Entries
:
[]
auxpb
.
LoadEntry
{
{
ResourceID
:
"website1"
,
AppKey
:
"path/1"
,
AppKey
:
"
/
path/1"
,
ValueJSON
:
`
{"name": "Wordpress", "version": "4.5.1", "safe
_
version": "5.6",
"state": "vulnerable", "vulninfo": "
FOO BAR PHP SHELL
"}`
,
{"
app
name": "Wordpress", "version": "4.5.1", "safeversion": "5.6",
"state": "vulnerable", "vulninfo": "
CVE-2019-17672
"}`
,
},
{
ResourceID
:
"website1"
,
AppKey
:
"path/2"
,
AppKey
:
"
/
path/2"
,
ValueJSON
:
`
{"name": "Wordpress-plugin", "version": "0.1", "safe_version": "0.2",
"state": "vulnerable", "vulninfo": "FOO BAR PHP SHELL"}`
,
{"appname": "Wordpress-plugin", "version": "0.1", "state": "ok"}`
,
},
{
ResourceID
:
"website2"
,
AppKey
:
"path/3"
,
AppKey
:
"
/
path/3"
,
ValueJSON
:
`
{"name": "Wordpress", "version": "4.5.1", "safe
_
version": "5.6",
"state": "vulnerable", "vulninfo": "
FOO BAR PHP SHELL
"}`
,
{"
app
name": "Wordpress", "version": "4.5.1", "safeversion": "5.6",
"state": "vulnerable", "vulninfo": "
CVE-2019-17672
"}`
,
},
},
},
nil
)
...
...
@@ -113,6 +112,11 @@ func TestWebapp_Get(t *testing.T) {
if
len
(
resp
.
Results
)
!=
2
{
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
)
{
...
...
@@ -137,6 +141,12 @@ func TestWebapp_Query_Find(t *testing.T) {
if
resp
.
Results
[
0
][
3
]
.
(
string
)
!=
"4.5.1"
{
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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment