2017-06-12 08:48:55 -05:00
package api
import (
2021-06-15 09:08:27 -05:00
"context"
2017-06-12 08:48:55 -05:00
"encoding/json"
2021-05-26 09:20:13 -05:00
"errors"
2018-02-19 04:12:56 -06:00
"fmt"
2020-06-22 11:00:39 -05:00
"io/ioutil"
2021-07-16 05:40:03 -05:00
"net/http"
2017-06-12 08:48:55 -05:00
"testing"
2022-03-10 11:19:50 -06:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
2017-06-12 08:48:55 -05:00
"github.com/grafana/grafana/pkg/api/dtos"
2021-01-15 07:43:20 -06:00
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/api/routing"
2017-06-12 08:48:55 -05:00
"github.com/grafana/grafana/pkg/bus"
2017-06-12 16:05:32 -05:00
"github.com/grafana/grafana/pkg/components/simplejson"
2021-09-22 09:28:40 -05:00
"github.com/grafana/grafana/pkg/infra/usagestats"
2020-03-04 05:57:20 -06:00
"github.com/grafana/grafana/pkg/models"
2022-03-10 05:58:18 -06:00
accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
2018-10-13 00:53:28 -05:00
"github.com/grafana/grafana/pkg/services/alerting"
2017-12-12 09:15:24 -06:00
"github.com/grafana/grafana/pkg/services/dashboards"
2022-02-16 07:15:44 -06:00
"github.com/grafana/grafana/pkg/services/dashboards/database"
service "github.com/grafana/grafana/pkg/services/dashboards/manager"
2022-01-26 11:44:20 -06:00
"github.com/grafana/grafana/pkg/services/featuremgmt"
2022-03-21 04:49:49 -05:00
"github.com/grafana/grafana/pkg/services/guardian"
2021-05-12 01:48:17 -05:00
"github.com/grafana/grafana/pkg/services/libraryelements"
2020-10-28 03:36:57 -05:00
"github.com/grafana/grafana/pkg/services/live"
2019-04-30 06:32:18 -05:00
"github.com/grafana/grafana/pkg/services/provisioning"
2020-12-15 12:09:04 -06:00
"github.com/grafana/grafana/pkg/services/quota"
2021-08-25 08:11:22 -05:00
"github.com/grafana/grafana/pkg/services/sqlstore"
2022-02-03 02:20:20 -06:00
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
2017-12-15 07:19:49 -06:00
"github.com/grafana/grafana/pkg/setting"
2021-10-11 07:30:59 -05:00
"github.com/grafana/grafana/pkg/web"
2017-06-12 08:48:55 -05:00
)
2020-06-22 11:00:39 -05:00
func TestGetHomeDashboard ( t * testing . T ) {
2021-07-16 05:40:03 -05:00
httpReq , err := http . NewRequest ( http . MethodGet , "" , nil )
require . NoError ( t , err )
2022-02-09 06:44:38 -06:00
httpReq . Header . Add ( "Content-Type" , "application/json" )
2021-10-11 07:30:59 -05:00
req := & models . ReqContext { SignedInUser : & models . SignedInUser { } , Context : & web . Context { Req : httpReq } }
2020-06-22 11:00:39 -05:00
cfg := setting . NewCfg ( )
cfg . StaticRootPath = "../../public/"
2021-03-17 10:06:10 -05:00
hs := & HTTPServer {
Cfg : cfg , Bus : bus . New ( ) ,
2021-11-01 04:53:33 -05:00
pluginStore : & fakePluginStore { } ,
2022-02-07 05:43:43 -06:00
SQLStore : mockstore . NewSQLStoreMock ( ) ,
2021-03-17 10:06:10 -05:00
}
2020-06-22 11:00:39 -05:00
tests := [ ] struct {
name string
defaultSetting string
expectedDashboardPath string
} {
{ name : "using default config" , defaultSetting : "" , expectedDashboardPath : "../../public/dashboards/home.json" } ,
{ name : "custom path" , defaultSetting : "../../public/dashboards/default.json" , expectedDashboardPath : "../../public/dashboards/default.json" } ,
}
for _ , tc := range tests {
t . Run ( tc . name , func ( t * testing . T ) {
dash := dtos . DashboardFullWithMeta { }
dash . Meta . IsHome = true
dash . Meta . FolderTitle = "General"
homeDashJSON , err := ioutil . ReadFile ( tc . expectedDashboardPath )
require . NoError ( t , err , "must be able to read expected dashboard file" )
hs . Cfg . DefaultHomeDashboardPath = tc . defaultSetting
bytes , err := simplejson . NewJson ( homeDashJSON )
require . NoError ( t , err , "must be able to encode file as JSON" )
dash . Dashboard = bytes
b , err := json . Marshal ( dash )
require . NoError ( t , err , "must be able to marshal object to JSON" )
res := hs . GetHomeDashboard ( req )
2021-01-15 07:43:20 -06:00
nr , ok := res . ( * response . NormalResponse )
2020-06-22 11:00:39 -05:00
require . True ( t , ok , "should return *NormalResponse" )
2021-01-15 07:43:20 -06:00
require . Equal ( t , b , nr . Body ( ) , "default home dashboard should equal content on disk" )
2020-06-22 11:00:39 -05:00
} )
}
}
2022-03-22 14:48:32 -05:00
func newTestLive ( t * testing . T , store * sqlstore . SQLStore ) * live . GrafanaLive {
2022-01-26 11:44:20 -06:00
features := featuremgmt . WithFeatures ( )
2021-08-25 08:11:22 -05:00
cfg := & setting . Cfg { AppURL : "http://localhost:3000/" }
2022-01-26 11:44:20 -06:00
cfg . IsFeatureToggleEnabled = features . IsEnabled
gLive , err := live . ProvideService ( nil , cfg ,
routing . NewRouteRegister ( ) ,
nil , nil , nil ,
2022-03-22 14:48:32 -05:00
store ,
2022-01-26 11:44:20 -06:00
nil ,
& usagestats . UsageStatsMock { T : t } ,
nil ,
2022-02-22 01:47:42 -06:00
features , nil )
2021-05-04 10:44:55 -05:00
require . NoError ( t , err )
return gLive
}
2018-02-19 04:12:56 -06:00
// This tests three main scenarios.
// If a user has access to execute an action on a dashboard:
// 1. and the dashboard is in a folder which does not have an acl
// 2. and the dashboard is in a folder which does have an acl
// 3. Post dashboard response tests
2018-01-30 07:09:30 -06:00
2020-11-13 02:52:38 -06:00
func TestDashboardAPIEndpoint ( t * testing . T ) {
t . Run ( "Given a dashboard with a parent folder which does not have an ACL" , func ( t * testing . T ) {
2022-02-07 05:43:43 -06:00
fakeDash := models . NewDashboard ( "Child dash" )
fakeDash . Id = 1
fakeDash . FolderId = 1
fakeDash . HasAcl = false
2017-06-12 08:48:55 -05:00
2022-02-07 05:43:43 -06:00
mockSQLStore := mockstore . NewSQLStoreMock ( )
mockSQLStore . ExpectedDashboard = fakeDash
2018-01-31 09:51:06 -06:00
2022-02-07 05:43:43 -06:00
hs := & HTTPServer {
2022-04-04 09:57:43 -05:00
Cfg : setting . NewCfg ( ) ,
pluginStore : & fakePluginStore { } ,
SQLStore : mockSQLStore ,
AccessControl : accesscontrolmock . New ( ) ,
Features : featuremgmt . WithFeatures ( ) ,
2022-02-07 05:43:43 -06:00
}
hs . SQLStore = mockSQLStore
2018-01-29 14:23:07 -06:00
2022-02-07 05:43:43 -06:00
setUp := func ( ) {
2020-11-13 02:52:38 -06:00
viewerRole := models . ROLE_VIEWER
editorRole := models . ROLE_EDITOR
2018-04-10 03:48:10 -05:00
2020-11-13 02:52:38 -06:00
aclMockResp := [ ] * models . DashboardAclInfoDTO {
{ Role : & viewerRole , Permission : models . PERMISSION_VIEW } ,
{ Role : & editorRole , Permission : models . PERMISSION_EDIT } ,
}
2022-03-21 04:49:49 -05:00
mockSQLStore . ExpectedDashboardAclInfoList = aclMockResp
guardian . InitLegacyGuardian ( mockSQLStore )
2020-11-13 02:52:38 -06:00
}
2017-06-22 16:43:55 -05:00
2018-01-30 07:09:30 -06:00
// This tests two scenarios:
// 1. user is an org viewer
// 2. user is an org editor
2020-11-13 02:52:38 -06:00
t . Run ( "When user is an Org Viewer" , func ( t * testing . T ) {
2020-03-04 05:57:20 -06:00
role := models . ROLE_VIEWER
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/uid/abcdefghi" ,
"/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
2022-02-07 05:43:43 -06:00
setUp ( )
sc . sqlStore = mockSQLStore
2022-02-16 07:15:44 -06:00
dash := getDashboardShouldReturn200 ( t , sc )
2020-11-13 02:52:38 -06:00
assert . False ( t , dash . Meta . CanEdit )
assert . False ( t , dash . Meta . CanSave )
assert . False ( t , dash . Meta . CanAdmin )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions/1" ,
"/api/dashboards/id/:dashboardId/versions/:id" , role , func ( sc * scenarioContext ) {
setUp ( )
2022-02-07 05:43:43 -06:00
sc . sqlStore = mockSQLStore
2018-01-31 09:46:31 -06:00
2022-02-07 05:43:43 -06:00
hs . callGetDashboardVersion ( sc )
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions" ,
"/api/dashboards/id/:dashboardId/versions" , role , func ( sc * scenarioContext ) {
setUp ( )
2022-02-07 05:43:43 -06:00
sc . sqlStore = mockSQLStore
2017-06-13 17:28:34 -05:00
2022-02-07 05:43:43 -06:00
hs . callGetDashboardVersions ( sc )
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 08:48:55 -05:00
} )
2020-11-13 02:52:38 -06:00
t . Run ( "When user is an Org Editor" , func ( t * testing . T ) {
2020-03-04 05:57:20 -06:00
role := models . ROLE_EDITOR
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/uid/abcdefghi" ,
"/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
2022-02-07 05:43:43 -06:00
setUp ( )
sc . sqlStore = mockSQLStore
2022-02-16 07:15:44 -06:00
dash := getDashboardShouldReturn200 ( t , sc )
2017-06-12 08:48:55 -05:00
2020-11-13 02:52:38 -06:00
assert . True ( t , dash . Meta . CanEdit )
assert . True ( t , dash . Meta . CanSave )
assert . False ( t , dash . Meta . CanAdmin )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions/1" ,
"/api/dashboards/id/:dashboardId/versions/:id" , role , func ( sc * scenarioContext ) {
setUp ( )
2022-02-07 05:43:43 -06:00
sc . sqlStore = mockSQLStore
hs . callGetDashboardVersion ( sc )
2018-01-31 09:46:31 -06:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 200 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions" ,
"/api/dashboards/id/:dashboardId/versions" , role , func ( sc * scenarioContext ) {
setUp ( )
2022-02-07 05:43:43 -06:00
hs . callGetDashboardVersions ( sc )
2017-06-13 17:28:34 -05:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 200 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 08:48:55 -05:00
} )
} )
2020-11-13 02:52:38 -06:00
t . Run ( "Given a dashboard with a parent folder which has an ACL" , func ( t * testing . T ) {
2022-02-07 05:43:43 -06:00
fakeDash := models . NewDashboard ( "Child dash" )
fakeDash . Id = 1
fakeDash . FolderId = 1
fakeDash . HasAcl = true
mockSQLStore := mockstore . NewSQLStoreMock ( )
mockSQLStore . ExpectedDashboard = fakeDash
2022-03-10 05:58:18 -06:00
cfg := setting . NewCfg ( )
features := featuremgmt . WithFeatures ( )
2022-03-22 14:48:32 -05:00
sql := sqlstore . InitTestDB ( t )
dashboardStore := database . ProvideDashboardStore ( sql )
2020-11-13 02:52:38 -06:00
hs := & HTTPServer {
2022-03-10 05:58:18 -06:00
Cfg : cfg ,
2022-03-22 14:48:32 -05:00
Live : newTestLive ( t , sql ) ,
2021-05-12 01:48:17 -05:00
LibraryPanelService : & mockLibraryPanelService { } ,
LibraryElementService : & mockLibraryElementService { } ,
2022-02-07 05:43:43 -06:00
SQLStore : mockSQLStore ,
2022-04-04 09:57:43 -05:00
AccessControl : accesscontrolmock . New ( ) ,
2022-03-10 05:58:18 -06:00
dashboardService : service . ProvideDashboardService (
cfg , dashboardStore , nil , features , accesscontrolmock . NewPermissionsServicesMock ( ) ,
) ,
2020-11-13 02:52:38 -06:00
}
2022-02-07 05:43:43 -06:00
hs . SQLStore = mockSQLStore
2017-06-12 08:48:55 -05:00
2022-02-07 05:43:43 -06:00
setUp := func ( ) {
2020-11-13 02:52:38 -06:00
origCanEdit := setting . ViewersCanEdit
t . Cleanup ( func ( ) {
setting . ViewersCanEdit = origCanEdit
} )
setting . ViewersCanEdit = false
2017-06-19 14:22:42 -05:00
2020-11-13 02:52:38 -06:00
aclMockResp := [ ] * models . DashboardAclInfoDTO {
{
DashboardId : 1 ,
Permission : models . PERMISSION_EDIT ,
UserId : 200 ,
} ,
}
2017-06-12 08:48:55 -05:00
2022-03-21 04:49:49 -05:00
mockSQLStore . ExpectedDashboardAclInfoList = aclMockResp
guardian . InitLegacyGuardian ( mockSQLStore )
2019-04-30 06:32:18 -05:00
}
2018-01-30 07:09:30 -06:00
// This tests six scenarios:
// 1. user is an org viewer AND has no permissions for this dashboard
// 2. user is an org editor AND has no permissions for this dashboard
// 3. user is an org viewer AND has been granted edit permission for the dashboard
// 4. user is an org viewer AND all viewers have edit permission for this dashboard
// 5. user is an org viewer AND has been granted an admin permission
// 6. user is an org editor AND has been granted a view permission
2020-11-13 02:52:38 -06:00
t . Run ( "When user is an Org Viewer and has no permissions for this dashboard" , func ( t * testing . T ) {
2020-03-04 05:57:20 -06:00
role := models . ROLE_VIEWER
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/uid/abcdefghi" ,
"/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
2022-02-07 05:43:43 -06:00
setUp ( )
sc . sqlStore = mockSQLStore
2020-11-13 02:52:38 -06:00
sc . handlerFunc = hs . GetDashboard
sc . fakeReqWithParams ( "GET" , sc . url , map [ string ] string { } ) . exec ( )
2022-02-07 05:43:43 -06:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2018-01-29 14:23:07 -06:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling DELETE on" , "DELETE" , "/api/dashboards/uid/abcdefghi" ,
"/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
2022-02-07 05:43:43 -06:00
setUp ( )
sc . sqlStore = mockSQLStore
hs . callDeleteDashboardByUID ( t , sc , nil )
2018-01-29 14:23:07 -06:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions/1" ,
"/api/dashboards/id/:dashboardId/versions/:id" , role , func ( sc * scenarioContext ) {
setUp ( )
2022-02-07 05:43:43 -06:00
sc . sqlStore = mockSQLStore
hs . callGetDashboardVersion ( sc )
2018-01-31 09:46:31 -06:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions" ,
"/api/dashboards/id/:dashboardId/versions" , role , func ( sc * scenarioContext ) {
setUp ( )
2022-02-07 05:43:43 -06:00
hs . callGetDashboardVersions ( sc )
2017-06-13 17:28:34 -05:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 08:48:55 -05:00
} )
2020-11-13 02:52:38 -06:00
t . Run ( "When user is an Org Editor and has no permissions for this dashboard" , func ( t * testing . T ) {
2020-03-04 05:57:20 -06:00
role := models . ROLE_EDITOR
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/uid/abcdefghi" ,
"/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
2022-02-07 05:43:43 -06:00
setUp ( )
sc . sqlStore = mockSQLStore
2020-11-13 02:52:38 -06:00
sc . handlerFunc = hs . GetDashboard
sc . fakeReqWithParams ( "GET" , sc . url , map [ string ] string { } ) . exec ( )
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2018-01-29 14:23:07 -06:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling DELETE on" , "DELETE" , "/api/dashboards/uid/abcdefghi" ,
"/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
2022-02-07 05:43:43 -06:00
setUp ( )
hs . callDeleteDashboardByUID ( t , sc , nil )
2018-01-29 14:23:07 -06:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions/1" ,
"/api/dashboards/id/:dashboardId/versions/:id" , role , func ( sc * scenarioContext ) {
setUp ( )
2022-02-07 05:43:43 -06:00
hs . callGetDashboardVersion ( sc )
2018-01-31 09:46:31 -06:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions" ,
"/api/dashboards/id/:dashboardId/versions" , role , func ( sc * scenarioContext ) {
setUp ( )
2022-02-07 05:43:43 -06:00
hs . callGetDashboardVersions ( sc )
2017-06-13 17:28:34 -05:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 08:48:55 -05:00
} )
2020-11-13 02:52:38 -06:00
t . Run ( "When user is an Org Viewer but has an edit permission" , func ( t * testing . T ) {
2020-03-04 05:57:20 -06:00
role := models . ROLE_VIEWER
2017-06-12 16:05:32 -05:00
2020-03-04 05:57:20 -06:00
mockResult := [ ] * models . DashboardAclInfoDTO {
{ OrgId : 1 , DashboardId : 2 , UserId : 1 , Permission : models . PERMISSION_EDIT } ,
2017-06-12 08:48:55 -05:00
}
2022-02-07 05:43:43 -06:00
setUpInner := func ( ) {
setUp ( )
2022-03-21 04:49:49 -05:00
mockSQLStore . ExpectedDashboardAclInfoList = mockResult
2020-11-13 02:52:38 -06:00
}
2022-02-07 05:43:43 -06:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/uid/abcdefghi" ,
"/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
2022-02-07 05:43:43 -06:00
setUpInner ( )
sc . sqlStore = mockSQLStore
2022-02-16 07:15:44 -06:00
dash := getDashboardShouldReturn200 ( t , sc )
2018-01-29 14:23:07 -06:00
2020-11-13 02:52:38 -06:00
assert . True ( t , dash . Meta . CanEdit )
assert . True ( t , dash . Meta . CanSave )
assert . False ( t , dash . Meta . CanAdmin )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-22 17:34:19 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling DELETE on" , "DELETE" , "/api/dashboards/uid/abcdefghi" , "/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
2022-02-07 05:43:43 -06:00
setUpInner ( )
mockDashboard := & dashboards . FakeDashboardService {
SaveDashboardResult : & models . Dashboard {
Id : fakeDash . Id ,
Uid : "uid" ,
Title : "Dash" ,
Slug : "dash" ,
Version : 2 ,
} ,
}
hs . callDeleteDashboardByUID ( t , sc , mockDashboard )
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 200 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-22 17:34:19 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions/1" , "/api/dashboards/id/:dashboardId/versions/:id" , role , func ( sc * scenarioContext ) {
setUpInner ( )
2022-02-07 05:43:43 -06:00
sc . sqlStore = mockSQLStore
hs . callGetDashboardVersion ( sc )
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 200 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-22 17:34:19 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions" , "/api/dashboards/id/:dashboardId/versions" , role , func ( sc * scenarioContext ) {
setUpInner ( )
2022-02-07 05:43:43 -06:00
hs . callGetDashboardVersions ( sc )
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 200 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-22 17:34:19 -05:00
} )
2020-11-13 02:52:38 -06:00
t . Run ( "When user is an Org Viewer and viewers can edit" , func ( t * testing . T ) {
2020-03-04 05:57:20 -06:00
role := models . ROLE_VIEWER
2017-12-15 07:19:49 -06:00
2022-02-07 05:43:43 -06:00
setUpInner := func ( ) {
setUp ( )
2017-12-15 07:19:49 -06:00
2020-11-13 02:52:38 -06:00
mockResult := [ ] * models . DashboardAclInfoDTO {
{ OrgId : 1 , DashboardId : 2 , UserId : 1 , Permission : models . PERMISSION_VIEW } ,
}
2022-03-21 04:49:49 -05:00
mockSQLStore . ExpectedDashboardAclInfoList = mockResult
2018-01-29 14:23:07 -06:00
2020-11-13 02:52:38 -06:00
origCanEdit := setting . ViewersCanEdit
t . Cleanup ( func ( ) {
setting . ViewersCanEdit = origCanEdit
2017-12-15 07:19:49 -06:00
} )
2020-11-13 02:52:38 -06:00
setting . ViewersCanEdit = true
}
2022-02-07 05:43:43 -06:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/uid/abcdefghi" , "/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
2022-02-07 05:43:43 -06:00
setUpInner ( )
2017-12-15 07:19:49 -06:00
2020-11-13 02:52:38 -06:00
require . True ( t , setting . ViewersCanEdit )
2022-02-07 05:43:43 -06:00
sc . sqlStore = mockSQLStore
2022-02-16 07:15:44 -06:00
dash := getDashboardShouldReturn200 ( t , sc )
2018-01-29 14:23:07 -06:00
2020-11-13 02:52:38 -06:00
assert . True ( t , dash . Meta . CanEdit )
assert . False ( t , dash . Meta . CanSave )
assert . False ( t , dash . Meta . CanAdmin )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-12-15 07:19:49 -06:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling DELETE on" , "DELETE" , "/api/dashboards/uid/abcdefghi" , "/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
2022-02-07 05:43:43 -06:00
setUpInner ( )
2018-01-31 09:46:31 -06:00
2022-02-07 05:43:43 -06:00
hs . callDeleteDashboardByUID ( t , sc , nil )
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-12-15 07:19:49 -06:00
} )
2020-11-13 02:52:38 -06:00
t . Run ( "When user is an Org Viewer but has an admin permission" , func ( t * testing . T ) {
2020-03-04 05:57:20 -06:00
role := models . ROLE_VIEWER
2017-06-22 17:34:19 -05:00
2022-02-07 05:43:43 -06:00
setUpInner := func ( ) {
setUp ( )
2020-11-13 02:52:38 -06:00
mockResult := [ ] * models . DashboardAclInfoDTO {
{ OrgId : 1 , DashboardId : 2 , UserId : 1 , Permission : models . PERMISSION_ADMIN } ,
}
2022-03-21 04:49:49 -05:00
mockSQLStore . ExpectedDashboardAclInfoList = mockResult
2017-06-22 17:34:19 -05:00
}
2022-02-07 05:43:43 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/uid/abcdefghi" , "/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
setUpInner ( )
sc . sqlStore = mockSQLStore
2022-02-16 07:15:44 -06:00
dash := getDashboardShouldReturn200 ( t , sc )
2018-01-29 14:23:07 -06:00
2020-11-13 02:52:38 -06:00
assert . True ( t , dash . Meta . CanEdit )
assert . True ( t , dash . Meta . CanSave )
assert . True ( t , dash . Meta . CanAdmin )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling DELETE on" , "DELETE" , "/api/dashboards/uid/abcdefghi" , "/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
2022-02-07 05:43:43 -06:00
setUpInner ( )
sc . sqlStore = mockSQLStore
hs . callDeleteDashboardByUID ( t , sc , & dashboards . FakeDashboardService { } )
2018-01-29 14:23:07 -06:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 200 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions/1" , "/api/dashboards/id/:dashboardId/versions/:id" , role , func ( sc * scenarioContext ) {
setUpInner ( )
2018-01-31 09:46:31 -06:00
2022-02-07 05:43:43 -06:00
hs . callGetDashboardVersion ( sc )
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 200 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions" , "/api/dashboards/id/:dashboardId/versions" , role , func ( sc * scenarioContext ) {
setUpInner ( )
2017-06-13 17:28:34 -05:00
2022-02-07 05:43:43 -06:00
hs . callGetDashboardVersions ( sc )
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 200 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 08:48:55 -05:00
} )
2020-11-13 02:52:38 -06:00
t . Run ( "When user is an Org Editor but has a view permission" , func ( t * testing . T ) {
2020-03-04 05:57:20 -06:00
role := models . ROLE_EDITOR
2017-06-12 16:05:32 -05:00
2022-02-07 05:43:43 -06:00
setUpInner := func ( ) {
setUp ( )
2017-06-12 08:48:55 -05:00
2020-11-13 02:52:38 -06:00
mockResult := [ ] * models . DashboardAclInfoDTO {
{ OrgId : 1 , DashboardId : 2 , UserId : 1 , Permission : models . PERMISSION_VIEW } ,
}
2022-03-21 04:49:49 -05:00
mockSQLStore . ExpectedDashboardAclInfoList = mockResult
2020-11-13 02:52:38 -06:00
}
2017-06-12 08:48:55 -05:00
2022-02-07 05:43:43 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/uid/abcdefghi" , "/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
setUpInner ( )
sc . sqlStore = mockSQLStore
2022-02-16 07:15:44 -06:00
dash := getDashboardShouldReturn200 ( t , sc )
2022-02-07 05:43:43 -06:00
2020-11-13 02:52:38 -06:00
assert . False ( t , dash . Meta . CanEdit )
assert . False ( t , dash . Meta . CanSave )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling DELETE on" , "DELETE" , "/api/dashboards/uid/abcdefghi" , "/api/dashboards/uid/:uid" , role , func ( sc * scenarioContext ) {
2022-02-07 05:43:43 -06:00
setUpInner ( )
hs . callDeleteDashboardByUID ( t , sc , nil )
2018-01-31 09:46:31 -06:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions/1" , "/api/dashboards/id/:dashboardId/versions/:id" , role , func ( sc * scenarioContext ) {
setUpInner ( )
2022-02-07 05:43:43 -06:00
hs . callGetDashboardVersion ( sc )
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-13 17:28:34 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/id/2/versions" , "/api/dashboards/id/:dashboardId/versions" , role , func ( sc * scenarioContext ) {
setUpInner ( )
2022-02-07 05:43:43 -06:00
hs . callGetDashboardVersions ( sc )
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2017-06-12 08:48:55 -05:00
} )
} )
2018-01-31 09:51:06 -06:00
2020-11-13 02:52:38 -06:00
t . Run ( "Given two dashboards with the same title in different folders" , func ( t * testing . T ) {
2020-03-04 05:57:20 -06:00
dashOne := models . NewDashboard ( "dash" )
2018-01-31 09:51:06 -06:00
dashOne . Id = 2
dashOne . FolderId = 1
dashOne . HasAcl = false
2020-03-04 05:57:20 -06:00
dashTwo := models . NewDashboard ( "dash" )
2018-01-31 09:51:06 -06:00
dashTwo . Id = 4
dashTwo . FolderId = 3
dashTwo . HasAcl = false
} )
2018-02-19 04:12:56 -06:00
2020-11-13 02:52:38 -06:00
t . Run ( "Post dashboard response tests" , func ( t * testing . T ) {
2022-03-10 11:19:50 -06:00
dashboardStore := & dashboards . FakeDashboardStore { }
2022-02-16 07:15:44 -06:00
defer dashboardStore . AssertExpectations ( t )
2018-02-19 04:12:56 -06:00
// This tests that a valid request returns correct response
2020-11-13 02:52:38 -06:00
t . Run ( "Given a correct request for creating a dashboard" , func ( t * testing . T ) {
const folderID int64 = 3
const dashID int64 = 2
2018-02-19 04:12:56 -06:00
2020-03-04 05:57:20 -06:00
cmd := models . SaveDashboardCommand {
2018-02-19 04:12:56 -06:00
OrgId : 1 ,
UserId : 5 ,
Dashboard : simplejson . NewFromAny ( map [ string ] interface { } {
"title" : "Dash" ,
} ) ,
Overwrite : true ,
2020-11-13 02:52:38 -06:00
FolderId : folderID ,
2018-02-19 04:12:56 -06:00
IsFolder : false ,
Message : "msg" ,
}
mock := & dashboards . FakeDashboardService {
2020-03-04 05:57:20 -06:00
SaveDashboardResult : & models . Dashboard {
2020-11-13 02:52:38 -06:00
Id : dashID ,
2018-02-19 04:12:56 -06:00
Uid : "uid" ,
Title : "Dash" ,
Slug : "dash" ,
Version : 2 ,
} ,
}
2022-02-16 07:15:44 -06:00
postDashboardScenario ( t , "When calling POST on" , "/api/dashboards" , "/api/dashboards" , cmd , mock , nil , func ( sc * scenarioContext ) {
2020-11-13 02:52:38 -06:00
callPostDashboardShouldReturnSuccess ( sc )
2018-02-19 04:12:56 -06:00
2020-11-13 02:52:38 -06:00
dto := mock . SavedDashboards [ 0 ]
assert . Equal ( t , cmd . OrgId , dto . OrgId )
assert . Equal ( t , cmd . UserId , dto . User . UserId )
assert . Equal ( t , folderID , dto . Dashboard . FolderId )
assert . Equal ( t , "Dash" , dto . Dashboard . Title )
assert . True ( t , dto . Overwrite )
assert . Equal ( t , "msg" , dto . Message )
result := sc . ToJSON ( )
assert . Equal ( t , "success" , result . Get ( "status" ) . MustString ( ) )
assert . Equal ( t , dashID , result . Get ( "id" ) . MustInt64 ( ) )
assert . Equal ( t , "uid" , result . Get ( "uid" ) . MustString ( ) )
assert . Equal ( t , "dash" , result . Get ( "slug" ) . MustString ( ) )
assert . Equal ( t , "/d/uid/dash" , result . Get ( "url" ) . MustString ( ) )
2018-02-19 04:12:56 -06:00
} )
} )
2021-05-26 09:20:13 -05:00
t . Run ( "Given a correct request for creating a dashboard with folder uid" , func ( t * testing . T ) {
const folderUid string = "folderUID"
const dashID int64 = 2
cmd := models . SaveDashboardCommand {
OrgId : 1 ,
UserId : 5 ,
Dashboard : simplejson . NewFromAny ( map [ string ] interface { } {
"title" : "Dash" ,
} ) ,
Overwrite : true ,
FolderUid : folderUid ,
IsFolder : false ,
Message : "msg" ,
}
mock := & dashboards . FakeDashboardService {
SaveDashboardResult : & models . Dashboard {
Id : dashID ,
Uid : "uid" ,
Title : "Dash" ,
Slug : "dash" ,
Version : 2 ,
} ,
}
mockFolder := & fakeFolderService {
GetFolderByUIDResult : & models . Folder { Id : 1 , Uid : "folderUID" , Title : "Folder" } ,
}
2022-02-16 07:15:44 -06:00
postDashboardScenario ( t , "When calling POST on" , "/api/dashboards" , "/api/dashboards" , cmd , mock , mockFolder , func ( sc * scenarioContext ) {
2021-05-26 09:20:13 -05:00
callPostDashboardShouldReturnSuccess ( sc )
dto := mock . SavedDashboards [ 0 ]
assert . Equal ( t , cmd . OrgId , dto . OrgId )
assert . Equal ( t , cmd . UserId , dto . User . UserId )
assert . Equal ( t , "Dash" , dto . Dashboard . Title )
assert . True ( t , dto . Overwrite )
assert . Equal ( t , "msg" , dto . Message )
result := sc . ToJSON ( )
assert . Equal ( t , "success" , result . Get ( "status" ) . MustString ( ) )
assert . Equal ( t , dashID , result . Get ( "id" ) . MustInt64 ( ) )
assert . Equal ( t , "uid" , result . Get ( "uid" ) . MustString ( ) )
assert . Equal ( t , "dash" , result . Get ( "slug" ) . MustString ( ) )
assert . Equal ( t , "/d/uid/dash" , result . Get ( "url" ) . MustString ( ) )
} )
} )
t . Run ( "Given a request with incorrect folder uid for creating a dashboard with" , func ( t * testing . T ) {
const folderUid string = "folderUID"
const dashID int64 = 2
cmd := models . SaveDashboardCommand {
OrgId : 1 ,
UserId : 5 ,
Dashboard : simplejson . NewFromAny ( map [ string ] interface { } {
"title" : "Dash" ,
} ) ,
Overwrite : true ,
FolderUid : folderUid ,
IsFolder : false ,
Message : "msg" ,
}
mock := & dashboards . FakeDashboardService {
SaveDashboardResult : & models . Dashboard {
Id : dashID ,
Uid : "uid" ,
Title : "Dash" ,
Slug : "dash" ,
Version : 2 ,
} ,
}
mockFolder := & fakeFolderService {
GetFolderByUIDError : errors . New ( "Error while searching Folder ID" ) ,
}
2022-02-16 07:15:44 -06:00
postDashboardScenario ( t , "When calling POST on" , "/api/dashboards" , "/api/dashboards" , cmd , mock , mockFolder , func ( sc * scenarioContext ) {
2021-05-26 09:20:13 -05:00
callPostDashboard ( sc )
assert . Equal ( t , 500 , sc . resp . Code )
} )
} )
2018-02-19 04:12:56 -06:00
// This tests that invalid requests returns expected error responses
2020-11-13 02:52:38 -06:00
t . Run ( "Given incorrect requests for creating a dashboard" , func ( t * testing . T ) {
2018-02-19 04:12:56 -06:00
testCases := [ ] struct {
SaveError error
ExpectedStatusCode int
} {
2020-03-04 05:57:20 -06:00
{ SaveError : models . ErrDashboardNotFound , ExpectedStatusCode : 404 } ,
{ SaveError : models . ErrFolderNotFound , ExpectedStatusCode : 400 } ,
{ SaveError : models . ErrDashboardWithSameUIDExists , ExpectedStatusCode : 400 } ,
{ SaveError : models . ErrDashboardWithSameNameInFolderExists , ExpectedStatusCode : 412 } ,
{ SaveError : models . ErrDashboardVersionMismatch , ExpectedStatusCode : 412 } ,
{ SaveError : models . ErrDashboardTitleEmpty , ExpectedStatusCode : 400 } ,
{ SaveError : models . ErrDashboardFolderCannotHaveParent , ExpectedStatusCode : 400 } ,
2018-10-13 00:53:28 -05:00
{ SaveError : alerting . ValidationError { Reason : "Mu" } , ExpectedStatusCode : 422 } ,
2020-03-04 05:57:20 -06:00
{ SaveError : models . ErrDashboardFailedGenerateUniqueUid , ExpectedStatusCode : 500 } ,
{ SaveError : models . ErrDashboardTypeMismatch , ExpectedStatusCode : 400 } ,
{ SaveError : models . ErrDashboardFolderWithSameNameAsDashboard , ExpectedStatusCode : 400 } ,
{ SaveError : models . ErrDashboardWithSameNameAsFolder , ExpectedStatusCode : 400 } ,
{ SaveError : models . ErrDashboardFolderNameExists , ExpectedStatusCode : 400 } ,
{ SaveError : models . ErrDashboardUpdateAccessDenied , ExpectedStatusCode : 403 } ,
{ SaveError : models . ErrDashboardInvalidUid , ExpectedStatusCode : 400 } ,
2020-07-21 04:12:01 -05:00
{ SaveError : models . ErrDashboardUidTooLong , ExpectedStatusCode : 400 } ,
2020-03-04 05:57:20 -06:00
{ SaveError : models . ErrDashboardCannotSaveProvisionedDashboard , ExpectedStatusCode : 400 } ,
{ SaveError : models . UpdatePluginDashboardError { PluginId : "plug" } , ExpectedStatusCode : 412 } ,
2018-02-19 04:12:56 -06:00
}
2020-03-04 05:57:20 -06:00
cmd := models . SaveDashboardCommand {
2018-02-19 04:12:56 -06:00
OrgId : 1 ,
Dashboard : simplejson . NewFromAny ( map [ string ] interface { } {
"title" : "" ,
} ) ,
}
for _ , tc := range testCases {
mock := & dashboards . FakeDashboardService {
SaveDashboardError : tc . SaveError ,
}
2020-11-13 02:52:38 -06:00
postDashboardScenario ( t , fmt . Sprintf ( "Expect '%s' error when calling POST on" , tc . SaveError . Error ( ) ) ,
2022-02-16 07:15:44 -06:00
"/api/dashboards" , "/api/dashboards" , cmd , mock , nil , func ( sc * scenarioContext ) {
2020-11-13 02:52:38 -06:00
callPostDashboard ( sc )
assert . Equal ( t , tc . ExpectedStatusCode , sc . resp . Code )
} )
2018-02-19 04:12:56 -06:00
}
} )
} )
2018-02-27 10:53:30 -06:00
2020-11-13 02:52:38 -06:00
t . Run ( "Given two dashboards being compared" , func ( t * testing . T ) {
2022-02-10 02:58:52 -06:00
dashboardvs := [ ] * models . DashboardVersion {
{
DashboardId : 1 ,
Version : 1 ,
Data : simplejson . NewFromAny ( map [ string ] interface { } {
"title" : "Dash1" ,
} ) } ,
{
DashboardId : 2 ,
Version : 2 ,
Data : simplejson . NewFromAny ( map [ string ] interface { } {
"title" : "Dash2" ,
} ) } ,
}
sqlmock := mockstore . SQLStoreMock { ExpectedDashboardVersions : dashboardvs }
2020-11-13 02:52:38 -06:00
setUp := func ( ) {
mockResult := [ ] * models . DashboardAclInfoDTO { }
2022-03-21 04:49:49 -05:00
sqlmock . ExpectedDashboardAclInfoList = mockResult
2020-11-13 02:52:38 -06:00
}
2018-02-27 10:53:30 -06:00
cmd := dtos . CalculateDiffOptions {
Base : dtos . CalculateDiffTarget {
DashboardId : 1 ,
Version : 1 ,
} ,
New : dtos . CalculateDiffTarget {
DashboardId : 2 ,
Version : 2 ,
} ,
DiffType : "basic" ,
}
2020-11-13 02:52:38 -06:00
t . Run ( "when user does not have permission" , func ( t * testing . T ) {
2020-03-04 05:57:20 -06:00
role := models . ROLE_VIEWER
2020-11-13 02:52:38 -06:00
postDiffScenario ( t , "When calling POST on" , "/api/dashboards/calculate-diff" , "/api/dashboards/calculate-diff" , cmd , role , func ( sc * scenarioContext ) {
setUp ( )
callPostDashboard ( sc )
assert . Equal ( t , 403 , sc . resp . Code )
2022-02-10 02:58:52 -06:00
} , & sqlmock )
2018-02-27 10:53:30 -06:00
} )
2020-11-13 02:52:38 -06:00
t . Run ( "when user does have permission" , func ( t * testing . T ) {
2020-03-04 05:57:20 -06:00
role := models . ROLE_ADMIN
2018-02-27 10:53:30 -06:00
2020-11-13 02:52:38 -06:00
postDiffScenario ( t , "When calling POST on" , "/api/dashboards/calculate-diff" , "/api/dashboards/calculate-diff" , cmd , role , func ( sc * scenarioContext ) {
setUp ( )
callPostDashboard ( sc )
assert . Equal ( t , 200 , sc . resp . Code )
2022-02-10 02:58:52 -06:00
} , & sqlmock )
2018-02-27 10:53:30 -06:00
} )
} )
2019-03-06 07:38:40 -06:00
2020-11-13 02:52:38 -06:00
t . Run ( "Given dashboard in folder being restored should restore to folder" , func ( t * testing . T ) {
const folderID int64 = 1
2022-02-07 05:43:43 -06:00
fakeDash := models . NewDashboard ( "Child dash" )
fakeDash . Id = 2
fakeDash . FolderId = folderID
fakeDash . HasAcl = false
2019-03-06 07:38:40 -06:00
mock := & dashboards . FakeDashboardService {
2020-03-04 05:57:20 -06:00
SaveDashboardResult : & models . Dashboard {
2019-03-06 07:38:40 -06:00
Id : 2 ,
Uid : "uid" ,
Title : "Dash" ,
Slug : "dash" ,
Version : 1 ,
} ,
}
cmd := dtos . RestoreDashboardVersionCommand {
Version : 1 ,
}
2022-02-07 05:43:43 -06:00
mockSQLStore := mockstore . NewSQLStoreMock ( )
mockSQLStore . ExpectedDashboard = fakeDash
2022-02-10 02:58:52 -06:00
mockSQLStore . ExpectedDashboardVersions = [ ] * models . DashboardVersion {
{
DashboardId : 2 ,
Version : 1 ,
Data : fakeDash . Data ,
} }
2020-11-13 02:52:38 -06:00
restoreDashboardVersionScenario ( t , "When calling POST on" , "/api/dashboards/id/1/restore" ,
"/api/dashboards/id/:dashboardId/restore" , mock , cmd , func ( sc * scenarioContext ) {
callRestoreDashboardVersion ( sc )
assert . Equal ( t , 200 , sc . resp . Code )
dto := mock . SavedDashboards [ 0 ]
2022-02-07 05:43:43 -06:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , folderID , dto . Dashboard . FolderId )
assert . Equal ( t , "Child dash" , dto . Dashboard . Title )
assert . Equal ( t , "Restored from version 1" , dto . Message )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2019-03-06 07:38:40 -06:00
} )
2020-11-13 02:52:38 -06:00
t . Run ( "Given dashboard in general folder being restored should restore to general folder" , func ( t * testing . T ) {
2022-02-07 05:43:43 -06:00
fakeDash := models . NewDashboard ( "Child dash" )
fakeDash . Id = 2
fakeDash . HasAcl = false
2019-03-06 07:38:40 -06:00
mock := & dashboards . FakeDashboardService {
2020-03-04 05:57:20 -06:00
SaveDashboardResult : & models . Dashboard {
2019-03-06 07:38:40 -06:00
Id : 2 ,
Uid : "uid" ,
Title : "Dash" ,
Slug : "dash" ,
Version : 1 ,
} ,
}
cmd := dtos . RestoreDashboardVersionCommand {
Version : 1 ,
}
2022-02-07 05:43:43 -06:00
mockSQLStore := mockstore . NewSQLStoreMock ( )
mockSQLStore . ExpectedDashboard = fakeDash
2022-02-10 02:58:52 -06:00
mockSQLStore . ExpectedDashboardVersions = [ ] * models . DashboardVersion {
{
DashboardId : 2 ,
Version : 1 ,
Data : fakeDash . Data ,
} }
2020-11-13 02:52:38 -06:00
restoreDashboardVersionScenario ( t , "When calling POST on" , "/api/dashboards/id/1/restore" ,
"/api/dashboards/id/:dashboardId/restore" , mock , cmd , func ( sc * scenarioContext ) {
callRestoreDashboardVersion ( sc )
assert . Equal ( t , 200 , sc . resp . Code )
dto := mock . SavedDashboards [ 0 ]
2022-02-07 05:43:43 -06:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , int64 ( 0 ) , dto . Dashboard . FolderId )
assert . Equal ( t , "Child dash" , dto . Dashboard . Title )
assert . Equal ( t , "Restored from version 1" , dto . Message )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2019-03-06 07:38:40 -06:00
} )
2019-04-10 06:29:10 -05:00
2020-11-13 02:52:38 -06:00
t . Run ( "Given provisioned dashboard" , func ( t * testing . T ) {
2022-03-21 04:49:49 -05:00
mockSQLStore := mockstore . NewSQLStoreMock ( )
2020-11-13 02:52:38 -06:00
setUp := func ( ) {
2022-03-21 04:49:49 -05:00
mockSQLStore . ExpectedDashboardAclInfoList = [ ] * models . DashboardAclInfoDTO {
{ OrgId : testOrgID , DashboardId : 1 , UserId : testUserID , Permission : models . PERMISSION_EDIT } ,
}
2020-11-13 02:52:38 -06:00
}
2022-02-16 07:15:44 -06:00
2022-02-07 05:43:43 -06:00
dataValue , err := simplejson . NewJson ( [ ] byte ( ` { "id": 1, "editable": true, "style": "dark"} ` ) )
require . NoError ( t , err )
mockSQLStore . ExpectedDashboard = & models . Dashboard { Id : 1 , Data : dataValue }
2019-04-30 06:32:18 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When calling GET on" , "GET" , "/api/dashboards/uid/dash" , "/api/dashboards/uid/:uid" , models . ROLE_EDITOR , func ( sc * scenarioContext ) {
setUp ( )
2022-02-16 07:15:44 -06:00
fakeProvisioningService := provisioning . NewProvisioningServiceMock ( context . Background ( ) )
fakeProvisioningService . GetDashboardProvisionerResolvedPathFunc = func ( name string ) string {
2019-04-30 06:32:18 -05:00
return "/tmp/grafana/dashboards"
}
2022-03-10 11:19:50 -06:00
dashboardStore := & dashboards . FakeDashboardStore { }
2022-02-16 07:15:44 -06:00
defer dashboardStore . AssertExpectations ( t )
2019-04-30 06:32:18 -05:00
2022-02-16 07:15:44 -06:00
dashboardStore . On ( "GetProvisionedDataByDashboardID" , mock . Anything ) . Return ( & models . DashboardProvisioning { ExternalId : "/dashboard1.json" } , nil ) . Once ( )
dash := getDashboardShouldReturn200WithConfig ( t , sc , fakeProvisioningService , dashboardStore )
assert . Equal ( t , "../../../dashboard1.json" , dash . Meta . ProvisionedExternalId , mockSQLStore )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2019-10-31 08:27:31 -05:00
2020-11-13 02:52:38 -06:00
loggedInUserScenarioWithRole ( t , "When allowUiUpdates is true and calling GET on" , "GET" , "/api/dashboards/uid/dash" , "/api/dashboards/uid/:uid" , models . ROLE_EDITOR , func ( sc * scenarioContext ) {
setUp ( )
2022-02-16 07:15:44 -06:00
fakeProvisioningService := provisioning . NewProvisioningServiceMock ( context . Background ( ) )
fakeProvisioningService . GetDashboardProvisionerResolvedPathFunc = func ( name string ) string {
2019-10-31 08:27:31 -05:00
return "/tmp/grafana/dashboards"
}
2022-02-16 07:15:44 -06:00
fakeProvisioningService . GetAllowUIUpdatesFromConfigFunc = func ( name string ) bool {
2019-10-31 08:27:31 -05:00
return true
}
hs := & HTTPServer {
2022-02-16 07:15:44 -06:00
Cfg : setting . NewCfg ( ) ,
ProvisioningService : fakeProvisioningService ,
LibraryPanelService : & mockLibraryPanelService { } ,
LibraryElementService : & mockLibraryElementService { } ,
dashboardProvisioningService : mockDashboardProvisioningService { } ,
SQLStore : mockSQLStore ,
2022-04-04 09:57:43 -05:00
AccessControl : accesscontrolmock . New ( ) ,
2019-10-31 08:27:31 -05:00
}
2022-02-07 05:43:43 -06:00
hs . callGetDashboard ( sc )
2019-10-31 08:27:31 -05:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , 200 , sc . resp . Code )
2019-10-31 08:27:31 -05:00
dash := dtos . DashboardFullWithMeta { }
err := json . NewDecoder ( sc . resp . Body ) . Decode ( & dash )
2020-11-13 02:52:38 -06:00
require . NoError ( t , err )
2019-10-31 08:27:31 -05:00
2020-11-13 02:52:38 -06:00
assert . Equal ( t , false , dash . Meta . Provisioned )
2022-02-07 05:43:43 -06:00
} , mockSQLStore )
2019-04-10 06:29:10 -05:00
} )
2017-06-12 08:48:55 -05:00
}
2017-06-12 16:05:32 -05:00
2022-02-16 07:15:44 -06:00
func getDashboardShouldReturn200WithConfig ( t * testing . T , sc * scenarioContext , provisioningService provisioning . ProvisioningService , dashboardStore dashboards . Store ) dtos . DashboardFullWithMeta {
t . Helper ( )
2019-04-30 06:32:18 -05:00
if provisioningService == nil {
2021-11-03 05:31:56 -05:00
provisioningService = provisioning . NewProvisioningServiceMock ( context . Background ( ) )
2019-04-30 06:32:18 -05:00
}
2022-02-16 07:15:44 -06:00
if dashboardStore == nil {
sql := sqlstore . InitTestDB ( t )
dashboardStore = database . ProvideDashboardStore ( sql )
}
2021-05-12 01:48:17 -05:00
libraryPanelsService := mockLibraryPanelService { }
libraryElementsService := mockLibraryElementService { }
2022-03-10 05:58:18 -06:00
cfg := setting . NewCfg ( )
features := featuremgmt . WithFeatures ( )
2021-05-12 01:48:17 -05:00
2019-04-30 06:32:18 -05:00
hs := & HTTPServer {
2022-03-10 05:58:18 -06:00
Cfg : cfg ,
LibraryPanelService : & libraryPanelsService ,
LibraryElementService : & libraryElementsService ,
SQLStore : sc . sqlStore ,
ProvisioningService : provisioningService ,
2022-04-04 09:57:43 -05:00
AccessControl : accesscontrolmock . New ( ) ,
2022-03-10 05:58:18 -06:00
dashboardProvisioningService : service . ProvideDashboardService (
cfg , dashboardStore , nil , features , accesscontrolmock . NewPermissionsServicesMock ( ) ,
) ,
2019-04-30 06:32:18 -05:00
}
2021-05-12 01:48:17 -05:00
2022-02-07 05:43:43 -06:00
hs . callGetDashboard ( sc )
2017-06-12 16:05:32 -05:00
2020-11-13 02:52:38 -06:00
require . Equal ( sc . t , 200 , sc . resp . Code )
2017-06-12 16:05:32 -05:00
dash := dtos . DashboardFullWithMeta { }
err := json . NewDecoder ( sc . resp . Body ) . Decode ( & dash )
2020-11-13 02:52:38 -06:00
require . NoError ( sc . t , err )
2017-06-12 16:05:32 -05:00
return dash
}
2022-02-16 07:15:44 -06:00
func getDashboardShouldReturn200 ( t * testing . T , sc * scenarioContext ) dtos . DashboardFullWithMeta {
return getDashboardShouldReturn200WithConfig ( t , sc , nil , nil )
2019-04-30 06:32:18 -05:00
}
2022-02-07 05:43:43 -06:00
func ( hs * HTTPServer ) callGetDashboard ( sc * scenarioContext ) {
2019-04-30 06:32:18 -05:00
sc . handlerFunc = hs . GetDashboard
2018-01-29 06:51:01 -06:00
sc . fakeReqWithParams ( "GET" , sc . url , map [ string ] string { } ) . exec ( )
}
2022-02-07 05:43:43 -06:00
func ( hs * HTTPServer ) callGetDashboardVersion ( sc * scenarioContext ) {
sc . handlerFunc = hs . GetDashboardVersion
2017-06-13 17:28:34 -05:00
sc . fakeReqWithParams ( "GET" , sc . url , map [ string ] string { } ) . exec ( )
}
2022-02-07 05:43:43 -06:00
func ( hs * HTTPServer ) callGetDashboardVersions ( sc * scenarioContext ) {
sc . handlerFunc = hs . GetDashboardVersions
2017-06-13 17:28:34 -05:00
sc . fakeReqWithParams ( "GET" , sc . url , map [ string ] string { } ) . exec ( )
}
2022-02-16 07:15:44 -06:00
func ( hs * HTTPServer ) callDeleteDashboardByUID ( t * testing . T ,
sc * scenarioContext , mockDashboard * dashboards . FakeDashboardService ) {
hs . dashboardService = mockDashboard
2021-01-20 02:28:10 -06:00
sc . handlerFunc = hs . DeleteDashboardByUID
2018-01-31 09:46:31 -06:00
sc . fakeReqWithParams ( "DELETE" , sc . url , map [ string ] string { } ) . exec ( )
}
2020-11-13 02:52:38 -06:00
func callPostDashboard ( sc * scenarioContext ) {
2017-06-12 16:05:32 -05:00
sc . fakeReqWithParams ( "POST" , sc . url , map [ string ] string { } ) . exec ( )
}
2020-11-13 02:52:38 -06:00
func callRestoreDashboardVersion ( sc * scenarioContext ) {
2019-03-06 07:38:40 -06:00
sc . fakeReqWithParams ( "POST" , sc . url , map [ string ] string { } ) . exec ( )
}
2020-11-13 02:52:38 -06:00
func callPostDashboardShouldReturnSuccess ( sc * scenarioContext ) {
callPostDashboard ( sc )
2018-01-30 16:37:54 -06:00
2020-11-13 02:52:38 -06:00
assert . Equal ( sc . t , 200 , sc . resp . Code )
2018-01-30 16:37:54 -06:00
}
2022-02-16 07:15:44 -06:00
func postDashboardScenario ( t * testing . T , desc string , url string , routePattern string , cmd models . SaveDashboardCommand , dashboardService dashboards . DashboardService , folderService dashboards . FolderService , fn scenarioFunc ) {
2020-11-13 02:52:38 -06:00
t . Run ( fmt . Sprintf ( "%s %s" , desc , url ) , func ( t * testing . T ) {
2020-12-15 12:09:04 -06:00
cfg := setting . NewCfg ( )
2019-02-11 14:12:01 -06:00
hs := HTTPServer {
2019-10-31 08:27:31 -05:00
Bus : bus . GetBus ( ) ,
2020-12-15 12:09:04 -06:00
Cfg : cfg ,
2021-11-03 05:31:56 -05:00
ProvisioningService : provisioning . NewProvisioningServiceMock ( context . Background ( ) ) ,
2022-03-22 14:48:32 -05:00
Live : newTestLive ( t , sqlstore . InitTestDB ( t ) ) ,
2020-12-15 12:09:04 -06:00
QuotaService : & quota . QuotaService {
Cfg : cfg ,
} ,
2021-11-01 04:53:33 -05:00
pluginStore : & fakePluginStore { } ,
2021-05-12 01:48:17 -05:00
LibraryPanelService : & mockLibraryPanelService { } ,
LibraryElementService : & mockLibraryElementService { } ,
2022-02-16 07:15:44 -06:00
dashboardService : dashboardService ,
folderService : folderService ,
2022-03-03 08:05:47 -06:00
Features : featuremgmt . WithFeatures ( ) ,
2019-02-11 14:12:01 -06:00
}
2020-11-13 02:52:38 -06:00
sc := setupScenarioContext ( t , url )
2021-01-15 07:43:20 -06:00
sc . defaultHandler = routing . Wrap ( func ( c * models . ReqContext ) response . Response {
2021-11-29 03:18:01 -06:00
c . Req . Body = mockRequestBody ( cmd )
2022-02-09 06:44:38 -06:00
c . Req . Header . Add ( "Content-Type" , "application/json" )
2017-06-12 16:05:32 -05:00
sc . context = c
2020-03-04 05:57:20 -06:00
sc . context . SignedInUser = & models . SignedInUser { OrgId : cmd . OrgId , UserId : cmd . UserId }
2017-06-12 16:05:32 -05:00
2021-11-29 03:18:01 -06:00
return hs . PostDashboard ( c )
2017-06-12 16:05:32 -05:00
} )
sc . m . Post ( routePattern , sc . defaultHandler )
fn ( sc )
} )
}
2018-01-29 12:27:53 -06:00
2022-02-10 02:58:52 -06:00
func postDiffScenario ( t * testing . T , desc string , url string , routePattern string , cmd dtos . CalculateDiffOptions , role models . RoleType , fn scenarioFunc , sqlmock sqlstore . Store ) {
2020-11-13 02:52:38 -06:00
t . Run ( fmt . Sprintf ( "%s %s" , desc , url ) , func ( t * testing . T ) {
2022-02-10 02:58:52 -06:00
cfg := setting . NewCfg ( )
hs := HTTPServer {
Cfg : cfg ,
Bus : bus . GetBus ( ) ,
ProvisioningService : provisioning . NewProvisioningServiceMock ( context . Background ( ) ) ,
2022-03-22 14:48:32 -05:00
Live : newTestLive ( t , sqlstore . InitTestDB ( t ) ) ,
2022-02-10 02:58:52 -06:00
QuotaService : & quota . QuotaService { Cfg : cfg } ,
LibraryPanelService : & mockLibraryPanelService { } ,
LibraryElementService : & mockLibraryElementService { } ,
SQLStore : sqlmock ,
}
2020-11-13 02:52:38 -06:00
sc := setupScenarioContext ( t , url )
2021-01-15 07:43:20 -06:00
sc . defaultHandler = routing . Wrap ( func ( c * models . ReqContext ) response . Response {
2021-11-29 03:18:01 -06:00
c . Req . Body = mockRequestBody ( cmd )
2022-02-09 06:44:38 -06:00
c . Req . Header . Add ( "Content-Type" , "application/json" )
2018-02-27 10:53:30 -06:00
sc . context = c
2020-03-04 05:57:20 -06:00
sc . context . SignedInUser = & models . SignedInUser {
2020-11-13 02:52:38 -06:00
OrgId : testOrgID ,
UserId : testUserID ,
2018-02-27 10:53:30 -06:00
}
sc . context . OrgRole = role
2022-02-10 02:58:52 -06:00
return hs . CalculateDashboardDiff ( c )
2018-02-27 10:53:30 -06:00
} )
sc . m . Post ( routePattern , sc . defaultHandler )
fn ( sc )
} )
}
2022-02-16 07:15:44 -06:00
func restoreDashboardVersionScenario ( t * testing . T , desc string , url string , routePattern string , mock * dashboards . FakeDashboardService , cmd dtos . RestoreDashboardVersionCommand , fn scenarioFunc , sqlStore sqlstore . Store ) {
2020-11-13 02:52:38 -06:00
t . Run ( fmt . Sprintf ( "%s %s" , desc , url ) , func ( t * testing . T ) {
2020-12-15 12:09:04 -06:00
cfg := setting . NewCfg ( )
2022-02-07 05:43:43 -06:00
mockSQLStore := mockstore . NewSQLStoreMock ( )
2019-03-06 07:38:40 -06:00
hs := HTTPServer {
2021-05-12 01:48:17 -05:00
Cfg : cfg ,
Bus : bus . GetBus ( ) ,
2021-11-03 05:31:56 -05:00
ProvisioningService : provisioning . NewProvisioningServiceMock ( context . Background ( ) ) ,
2022-03-22 14:48:32 -05:00
Live : newTestLive ( t , sqlstore . InitTestDB ( t ) ) ,
2021-05-12 01:48:17 -05:00
QuotaService : & quota . QuotaService { Cfg : cfg } ,
LibraryPanelService : & mockLibraryPanelService { } ,
LibraryElementService : & mockLibraryElementService { } ,
2022-02-16 07:15:44 -06:00
dashboardService : mock ,
2022-02-07 05:43:43 -06:00
SQLStore : sqlStore ,
2022-03-03 08:05:47 -06:00
Features : featuremgmt . WithFeatures ( ) ,
2019-03-06 07:38:40 -06:00
}
2020-11-13 02:52:38 -06:00
sc := setupScenarioContext ( t , url )
2022-02-07 05:43:43 -06:00
sc . sqlStore = mockSQLStore
2021-01-15 07:43:20 -06:00
sc . defaultHandler = routing . Wrap ( func ( c * models . ReqContext ) response . Response {
2021-11-29 03:18:01 -06:00
c . Req . Body = mockRequestBody ( cmd )
2022-02-09 06:44:38 -06:00
c . Req . Header . Add ( "Content-Type" , "application/json" )
2019-03-06 07:38:40 -06:00
sc . context = c
2020-03-04 05:57:20 -06:00
sc . context . SignedInUser = & models . SignedInUser {
2020-11-13 02:52:38 -06:00
OrgId : testOrgID ,
UserId : testUserID ,
2019-03-06 07:38:40 -06:00
}
2020-03-04 05:57:20 -06:00
sc . context . OrgRole = models . ROLE_ADMIN
2019-03-06 07:38:40 -06:00
2021-11-29 03:18:01 -06:00
return hs . RestoreDashboardVersion ( c )
2019-03-06 07:38:40 -06:00
} )
sc . m . Post ( routePattern , sc . defaultHandler )
fn ( sc )
} )
}
2018-03-22 16:13:46 -05:00
func ( sc * scenarioContext ) ToJSON ( ) * simplejson . Json {
2018-01-29 12:27:53 -06:00
var result * simplejson . Json
err := json . NewDecoder ( sc . resp . Body ) . Decode ( & result )
2020-11-13 02:52:38 -06:00
require . NoError ( sc . t , err )
2018-01-29 12:27:53 -06:00
return result
}
2019-10-31 08:27:31 -05:00
type mockDashboardProvisioningService struct {
2021-03-12 04:51:02 -06:00
dashboards . DashboardProvisioningService
2019-10-31 08:27:31 -05:00
}
2021-03-17 10:06:10 -05:00
func ( s mockDashboardProvisioningService ) GetProvisionedDashboardDataByDashboardID ( dashboardID int64 ) (
* models . DashboardProvisioning , error ) {
return nil , nil
2019-10-31 08:27:31 -05:00
}
2021-05-12 01:48:17 -05:00
type mockLibraryPanelService struct {
}
2021-09-27 02:04:36 -05:00
func ( m * mockLibraryPanelService ) LoadLibraryPanelsForDashboard ( c context . Context , dash * models . Dashboard ) error {
2021-05-12 01:48:17 -05:00
return nil
}
func ( m * mockLibraryPanelService ) CleanLibraryPanelsForDashboard ( dash * models . Dashboard ) error {
return nil
}
2021-09-27 02:04:36 -05:00
func ( m * mockLibraryPanelService ) ConnectLibraryPanelsForDashboard ( c context . Context , signedInUser * models . SignedInUser , dash * models . Dashboard ) error {
2021-05-12 01:48:17 -05:00
return nil
}
2021-09-27 02:04:36 -05:00
func ( m * mockLibraryPanelService ) ImportLibraryPanelsForDashboard ( c context . Context , signedInUser * models . SignedInUser , dash * models . Dashboard , folderID int64 ) error {
2021-09-20 03:58:24 -05:00
return nil
}
2021-05-12 01:48:17 -05:00
type mockLibraryElementService struct {
}
2021-09-27 02:04:36 -05:00
func ( l * mockLibraryElementService ) CreateElement ( c context . Context , signedInUser * models . SignedInUser , cmd libraryelements . CreateLibraryElementCommand ) ( libraryelements . LibraryElementDTO , error ) {
2021-09-20 03:58:24 -05:00
return libraryelements . LibraryElementDTO { } , nil
}
// GetElement gets an element from a UID.
2021-09-27 02:04:36 -05:00
func ( l * mockLibraryElementService ) GetElement ( c context . Context , signedInUser * models . SignedInUser , UID string ) ( libraryelements . LibraryElementDTO , error ) {
2021-05-12 01:48:17 -05:00
return libraryelements . LibraryElementDTO { } , nil
}
// GetElementsForDashboard gets all connected elements for a specific dashboard.
2021-09-27 02:04:36 -05:00
func ( l * mockLibraryElementService ) GetElementsForDashboard ( c context . Context , dashboardID int64 ) ( map [ string ] libraryelements . LibraryElementDTO , error ) {
2021-05-12 01:48:17 -05:00
return map [ string ] libraryelements . LibraryElementDTO { } , nil
}
// ConnectElementsToDashboard connects elements to a specific dashboard.
2021-09-27 02:04:36 -05:00
func ( l * mockLibraryElementService ) ConnectElementsToDashboard ( c context . Context , signedInUser * models . SignedInUser , elementUIDs [ ] string , dashboardID int64 ) error {
2021-05-12 01:48:17 -05:00
return nil
}
// DisconnectElementsFromDashboard disconnects elements from a specific dashboard.
2021-09-27 02:04:36 -05:00
func ( l * mockLibraryElementService ) DisconnectElementsFromDashboard ( c context . Context , dashboardID int64 ) error {
2021-05-12 01:48:17 -05:00
return nil
}
// DeleteLibraryElementsInFolder deletes all elements for a specific folder.
2021-09-27 02:04:36 -05:00
func ( l * mockLibraryElementService ) DeleteLibraryElementsInFolder ( c context . Context , signedInUser * models . SignedInUser , folderUID string ) error {
2021-05-12 01:48:17 -05:00
return nil
}