aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/app
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-10-11 13:17:50 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-10-15 08:34:09 +0000
commitb9fb2ea80e9852ae6465fcb3b822ca9ffa3306bd (patch)
tree6ef60254c3832271607cd34823308104ed8284cf /dashboard/app
parentbea340a021473d87bbbd5da6e88e575cc5e71cb0 (diff)
dashboard/api: add Client type
Diffstat (limited to 'dashboard/app')
-rw-r--r--dashboard/app/public_json_api.go6
-rw-r--r--dashboard/app/public_json_api_test.go28
-rw-r--r--dashboard/app/util_test.go34
3 files changed, 52 insertions, 16 deletions
diff --git a/dashboard/app/public_json_api.go b/dashboard/app/public_json_api.go
index 05d0de441..ce1c674be 100644
--- a/dashboard/app/public_json_api.go
+++ b/dashboard/app/public_json_api.go
@@ -11,7 +11,7 @@ import (
func getExtAPIDescrForBugPage(bugPage *uiBugPage) *api.Bug {
return &api.Bug{
- Version: 1,
+ Version: api.Version,
Title: bugPage.Bug.Title,
ID: bugPage.Bug.ID,
Discussions: func() []string {
@@ -81,7 +81,7 @@ func getExtAPIDescrForBugGroups(bugGroups []*uiBugGroup) *api.BugGroup {
}
}
return &api.BugGroup{
- Version: 1,
+ Version: api.Version,
Bugs: bugs,
}
}
@@ -115,7 +115,7 @@ type publicAPIBackports struct {
func getExtAPIDescrForBackports(groups []*uiBackportGroup) *publicAPIBackports {
return &publicAPIBackports{
- Version: 1,
+ Version: api.Version,
List: func() []publicMissingBackport {
var res []publicMissingBackport
for _, group := range groups {
diff --git a/dashboard/app/public_json_api_test.go b/dashboard/app/public_json_api_test.go
index ebf943438..82cf9c320 100644
--- a/dashboard/app/public_json_api_test.go
+++ b/dashboard/app/public_json_api_test.go
@@ -7,6 +7,7 @@ import (
"fmt"
"testing"
+ "github.com/google/syzkaller/dashboard/api"
"github.com/google/syzkaller/dashboard/dashapi"
)
@@ -222,3 +223,30 @@ func TestJSONAPICauseBisection(t *testing.T) {
]
}`)
}
+
+func TestPublicJSONAPI(t *testing.T) {
+ c := NewCtx(t)
+ defer c.Close()
+
+ client := c.makeClient(clientPublic, keyPublic, true)
+ build := testBuild(1)
+ client.UploadBuild(build)
+ client.ReportCrash(testCrashWithRepro(build, 1))
+ rep := client.pollBug()
+ client.updateBug(rep.ID, dashapi.BugStatusUpstream, "")
+ _ = client.pollBug()
+
+ cli := c.makeAPIClient()
+ bugs, err := cli.BugGroups("access-public", api.BugGroupAll)
+ c.expectOK(err)
+ c.expectEQ(len(bugs), 1)
+ c.expectEQ(bugs[0].Title, "title1")
+
+ bug, err := cli.Bug(bugs[0].Link)
+ c.expectOK(err)
+ c.expectEQ(bug.Title, "title1")
+
+ config, err := cli.Text(bug.Crashes[0].KernelConfigLink)
+ c.expectOK(err)
+ c.expectEQ(config, []byte("config1"))
+}
diff --git a/dashboard/app/util_test.go b/dashboard/app/util_test.go
index f30581095..f865ff612 100644
--- a/dashboard/app/util_test.go
+++ b/dashboard/app/util_test.go
@@ -26,6 +26,7 @@ import (
"time"
"github.com/google/go-cmp/cmp"
+ "github.com/google/syzkaller/dashboard/api"
"github.com/google/syzkaller/dashboard/dashapi"
"github.com/google/syzkaller/pkg/email"
"github.com/google/syzkaller/pkg/subsystem"
@@ -496,18 +497,6 @@ type apiClient struct {
}
func (c *Ctx) makeClient(client, key string, failOnErrors bool) *apiClient {
- doer := func(r *http.Request) (*http.Response, error) {
- r = registerRequest(r, c)
- r = r.WithContext(c.transformContext(r.Context()))
- w := httptest.NewRecorder()
- http.DefaultServeMux.ServeHTTP(w, r)
- res := &http.Response{
- StatusCode: w.Code,
- Status: http.StatusText(w.Code),
- Body: io.NopCloser(w.Result().Body),
- }
- return res, nil
- }
logger := func(msg string, args ...interface{}) {
c.t.Logf("%v: "+msg, append([]interface{}{caller(3)}, args...)...)
}
@@ -516,7 +505,7 @@ func (c *Ctx) makeClient(client, key string, failOnErrors bool) *apiClient {
c.t.Fatalf("\n%v: %v", caller(2), err)
}
}
- dash, err := dashapi.NewCustom(client, "", key, c.inst.NewRequest, doer, logger, errorHandler)
+ dash, err := dashapi.NewCustom(client, "", key, c.inst.NewRequest, c.httpDoer(), logger, errorHandler)
if err != nil {
panic(fmt.Sprintf("Impossible error: %v", err))
}
@@ -526,6 +515,25 @@ func (c *Ctx) makeClient(client, key string, failOnErrors bool) *apiClient {
}
}
+func (c *Ctx) makeAPIClient() *api.Client {
+ return api.NewTestClient(c.inst.NewRequest, c.httpDoer())
+}
+
+func (c *Ctx) httpDoer() func(*http.Request) (*http.Response, error) {
+ return func(r *http.Request) (*http.Response, error) {
+ r = registerRequest(r, c)
+ r = r.WithContext(c.transformContext(r.Context()))
+ w := httptest.NewRecorder()
+ http.DefaultServeMux.ServeHTTP(w, r)
+ res := &http.Response{
+ StatusCode: w.Code,
+ Status: http.StatusText(w.Code),
+ Body: io.NopCloser(w.Result().Body),
+ }
+ return res, nil
+ }
+}
+
func (client *apiClient) pollBugs(expect int) []*dashapi.BugReport {
resp, _ := client.ReportingPollBugs("test")
if len(resp.Reports) != expect {