|
|
@ -117,56 +117,53 @@ func TestIntegrationIndexViewAnalytics(t *testing.T) { |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// can be removed once ff is removed
|
|
|
|
for _, tc := range testCases { |
|
|
|
authBrokerStates := map[string]bool{"none": false, "authnService": true} |
|
|
|
t.Run(tc.name, func(t *testing.T) { |
|
|
|
|
|
|
|
grafDir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{ |
|
|
|
for k, enabled := range authBrokerStates { |
|
|
|
AuthBrokerEnabled: true, |
|
|
|
for _, tc := range testCases { |
|
|
|
}) |
|
|
|
t.Run(tc.name+"-"+k, func(t *testing.T) { |
|
|
|
addr, store := testinfra.StartGrafana(t, grafDir, cfgPath) |
|
|
|
grafDir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{AuthBrokerEnabled: enabled}) |
|
|
|
createdUser := testinfra.CreateUser(t, store, user.CreateUserCommand{ |
|
|
|
addr, store := testinfra.StartGrafana(t, grafDir, cfgPath) |
|
|
|
Login: "admin", |
|
|
|
createdUser := testinfra.CreateUser(t, store, user.CreateUserCommand{ |
|
|
|
Password: "admin", |
|
|
|
Login: "admin", |
|
|
|
Email: "admin@grafana.com", |
|
|
|
Password: "admin", |
|
|
|
OrgID: 1, |
|
|
|
Email: "admin@grafana.com", |
|
|
|
}) |
|
|
|
OrgID: 1, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
secretsService := secretsManager.SetupTestService(t, database.ProvideSecretsStore(store)) |
|
|
|
secretsService := secretsManager.SetupTestService(t, database.ProvideSecretsStore(store)) |
|
|
|
authInfoStore := databaseAuthInfo.ProvideAuthInfoStore(store, secretsService, nil) |
|
|
|
authInfoStore := databaseAuthInfo.ProvideAuthInfoStore(store, secretsService, nil) |
|
|
|
|
|
|
|
|
|
|
|
// insert user_auth relationship
|
|
|
|
// insert user_auth relationship
|
|
|
|
|
|
|
|
err := authInfoStore.SetAuthInfo(context.Background(), &login.SetAuthInfoCommand{ |
|
|
|
|
|
|
|
AuthModule: tc.authModule, |
|
|
|
|
|
|
|
AuthId: tc.setID, |
|
|
|
|
|
|
|
UserId: createdUser.ID, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
if tc.secondModule != "" { |
|
|
|
|
|
|
|
// wait for the user_auth relationship to be inserted. TOFIX: this is a hack
|
|
|
|
|
|
|
|
time.Sleep(1 * time.Second) |
|
|
|
err := authInfoStore.SetAuthInfo(context.Background(), &login.SetAuthInfoCommand{ |
|
|
|
err := authInfoStore.SetAuthInfo(context.Background(), &login.SetAuthInfoCommand{ |
|
|
|
AuthModule: tc.authModule, |
|
|
|
AuthModule: tc.secondModule, |
|
|
|
AuthId: tc.setID, |
|
|
|
AuthId: tc.secondID, |
|
|
|
UserId: createdUser.ID, |
|
|
|
UserId: createdUser.ID, |
|
|
|
}) |
|
|
|
}) |
|
|
|
require.NoError(t, err) |
|
|
|
require.NoError(t, err) |
|
|
|
if tc.secondModule != "" { |
|
|
|
} |
|
|
|
// wait for the user_auth relationship to be inserted. TOFIX: this is a hack
|
|
|
|
|
|
|
|
time.Sleep(1 * time.Second) |
|
|
|
// nolint:bodyclose
|
|
|
|
err := authInfoStore.SetAuthInfo(context.Background(), &login.SetAuthInfoCommand{ |
|
|
|
response, html := makeRequest(t, addr, "admin", "admin") |
|
|
|
AuthModule: tc.secondModule, |
|
|
|
assert.Equal(t, http.StatusOK, response.StatusCode) |
|
|
|
AuthId: tc.secondID, |
|
|
|
|
|
|
|
UserId: createdUser.ID, |
|
|
|
// parse User.Analytics HTML view into user.AnalyticsSettings model
|
|
|
|
}) |
|
|
|
parsedHTML := strings.Split(html, "analytics\":")[1] |
|
|
|
require.NoError(t, err) |
|
|
|
parsedHTML = strings.Split(parsedHTML, "},\n")[0] |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var analyticsSettings user.AnalyticsSettings |
|
|
|
// nolint:bodyclose
|
|
|
|
require.NoError(t, json.Unmarshal([]byte(parsedHTML), &analyticsSettings)) |
|
|
|
response, html := makeRequest(t, addr, "admin", "admin") |
|
|
|
|
|
|
|
assert.Equal(t, http.StatusOK, response.StatusCode) |
|
|
|
require.NotEmpty(t, analyticsSettings.IntercomIdentifier) |
|
|
|
|
|
|
|
require.Equal(t, tc.wantIdentifier, analyticsSettings.Identifier) |
|
|
|
// parse User.Analytics HTML view into user.AnalyticsSettings model
|
|
|
|
}) |
|
|
|
parsedHTML := strings.Split(html, "analytics\":")[1] |
|
|
|
|
|
|
|
parsedHTML = strings.Split(parsedHTML, "},\n")[0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var analyticsSettings user.AnalyticsSettings |
|
|
|
|
|
|
|
require.NoError(t, json.Unmarshal([]byte(parsedHTML), &analyticsSettings)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require.NotEmpty(t, analyticsSettings.IntercomIdentifier) |
|
|
|
|
|
|
|
require.Equal(t, tc.wantIdentifier, analyticsSettings.Identifier) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|