corso/src/internal/tester/resource_owners.go
neha_gupta 4087b69a39
Enhancement Sanity Test: verify permissions and defined data (#2938)
<!-- PR description-->
onedrive -  
- verify permissions - grantedToV2 and roles 
- recursively check subfolder's data and permission

Exchange -
- since the data in email is huge, create custom data and check if that data is getting restored properly
 
#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [x] 🤖 Supportability/Tests
- [x] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #<issue>

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E
2023-04-03 10:43:48 +00:00

165 lines
5.9 KiB
Go

package tester
import (
"context"
"os"
"strings"
"testing"
"github.com/alcionai/clues"
"github.com/stretchr/testify/require"
"github.com/alcionai/corso/src/pkg/logger"
)
// M365TenantID returns a tenantID string representing the azureTenantID described
// by either the env var AZURE_TENANT_ID, the corso_test.toml config
// file or the default value (in that order of priority). The default is a
// last-attempt fallback that will only work on alcion's testing org.
func M365TenantID(t *testing.T) string {
cfg, err := readTestConfig()
require.NoError(t, err, "retrieving m365 tenant ID from test configuration", clues.ToCore(err))
return cfg[TestCfgAzureTenantID]
}
// M365TenantID returns a tenantID string representing the azureTenantID described
// by either the env var AZURE_TENANT_ID, the corso_test.toml config
// file or the default value (in that order of priority). The default is a
// last-attempt fallback that will only work on alcion's testing org.
func GetM365TenantID(ctx context.Context) string {
cfg, err := readTestConfig()
if err != nil {
logger.Ctx(ctx).Error(err, "retrieving m365 tenant ID from test configuration")
}
return cfg[TestCfgAzureTenantID]
}
// M365UserID returns an userID string representing the m365UserID described
// by either the env var CORSO_M365_TEST_USER_ID, the corso_test.toml config
// file or the default value (in that order of priority). The default is a
// last-attempt fallback that will only work on alcion's testing org.
func M365UserID(t *testing.T) string {
cfg, err := readTestConfig()
require.NoError(t, err, "retrieving m365 user id from test configuration", clues.ToCore(err))
return cfg[TestCfgUserID]
}
// GetM365UserID returns an userID string representing the m365UserID described
// by either the env var CORSO_M365_TEST_USER_ID, the corso_test.toml config
// file or the default value (in that order of priority). The default is a
// last-attempt fallback that will only work on alcion's testing org.
func GetM365UserID(ctx context.Context) string {
cfg, err := readTestConfig()
if err != nil {
logger.Ctx(ctx).Error(err, "retrieving m365 user id from test configuration")
}
return cfg[TestCfgUserID]
}
// SecondaryM365UserID returns an userID string representing the m365UserID
// described by either the env var CORSO_SECONDARY_M365_TEST_USER_ID, the
// corso_test.toml config file or the default value (in that order of priority).
// The default is a last-attempt fallback that will only work on alcion's
// testing org.
func SecondaryM365UserID(t *testing.T) string {
cfg, err := readTestConfig()
require.NoError(t, err, "retrieving secondary m365 user id from test configuration", clues.ToCore(err))
return cfg[TestCfgSecondaryUserID]
}
// LoadTestM365SiteID returns a siteID string representing the m365SiteID
// described by either the env var CORSO_M365_LOAD_TEST_SITE_ID, the
// corso_test.toml config file or the default value (in that order of priority).
// The default is a last-attempt fallback that will only work on alcion's
// testing org.
func LoadTestM365SiteID(t *testing.T) string {
cfg, err := readTestConfig()
require.NoError(t, err, "retrieving load test m365 site id from test configuration", clues.ToCore(err))
// TODO: load test site id, not standard test site id
return cfg[TestCfgSiteID]
}
// LoadTestM365UserID returns an userID string representing the m365UserID
// described by either the env var CORSO_M365_LOAD_TEST_USER_ID, the
// corso_test.toml config file or the default value (in that order of priority).
// The default is a last-attempt fallback that will only work on alcion's
// testing org.
func LoadTestM365UserID(t *testing.T) string {
cfg, err := readTestConfig()
require.NoError(t, err, "retrieving load test m365 user id from test configuration", clues.ToCore(err))
return cfg[TestCfgLoadTestUserID]
}
// expects cfg value to be a string representing an array such as:
// ["site1\,uuid","site2\,uuid"]
// the delimeter must be a |.
func LoadTestM365OrgSites(t *testing.T) []string {
cfg, err := readTestConfig()
require.NoError(t, err, "retrieving load test m365 org sites from test configuration", clues.ToCore(err))
// TODO: proper handling of site slice input.
// sites := cfg[TestCfgLoadTestOrgSites]
// sites = strings.TrimPrefix(sites, "[")
// sites = strings.TrimSuffix(sites, "]")
// sites = strings.ReplaceAll(sites, `"`, "")
// sites = strings.ReplaceAll(sites, `'`, "")
// sites = strings.ReplaceAll(sites, "|", ",")
// return strings.Split(sites, ",")
return []string{cfg[TestCfgSiteID]}
}
// expects cfg value to be a string representing an array such as:
// ["foo@example.com","bar@example.com"]
// the delimeter may be either a , or |.
func LoadTestM365OrgUsers(t *testing.T) []string {
cfg, err := readTestConfig()
require.NoError(t, err, "retrieving load test m365 org users from test configuration", clues.ToCore(err))
users := cfg[TestCfgLoadTestOrgUsers]
users = strings.TrimPrefix(users, "[")
users = strings.TrimSuffix(users, "]")
users = strings.ReplaceAll(users, `"`, "")
users = strings.ReplaceAll(users, `'`, "")
users = strings.ReplaceAll(users, "|", ",")
// a hack to skip using certain users when those accounts are
// temporarily being co-opted for non-testing purposes.
sl := strings.Split(users, ",")
remove := os.Getenv("IGNORE_LOAD_TEST_USER_ID")
if len(remove) == 0 {
return sl
}
idx := -1
for i, s := range sl {
if s == remove {
idx = i
break
}
}
return append(sl[:idx], sl[idx+1:]...)
}
// M365SiteID returns a siteID string representing the m365SiteID described
// by either the env var CORSO_M365_TEST_SITE_ID, the corso_test.toml config
// file or the default value (in that order of priority). The default is a
// last-attempt fallback that will only work on alcion's testing org.
func M365SiteID(t *testing.T) string {
cfg, err := readTestConfig()
require.NoError(t, err, "retrieving m365 site id from test configuration", clues.ToCore(err))
return cfg[TestCfgSiteID]
}