private static LabResponse CreateLabResponseFromResultString(string result)
        {
            LabResponse response = JsonConvert.DeserializeObject <LabResponse>(result);
            LabUser     user     = JsonConvert.DeserializeObject <LabUser>(result);

            if (!string.IsNullOrEmpty(user.HomeTenantId) && !string.IsNullOrEmpty(user.HomeUPN))
            {
                user.InitializeHomeUser();
            }

            return(response);
        }
Esempio n. 2
0
        private LabResponse GetLabResponseFromApi(UserQuery query)
        {
            //Fetch user
            string result = RunQuery(query);

            if (string.IsNullOrWhiteSpace(result))
            {
                throw new LabUserNotFoundException(query, "No lab user with specified parameters exists");
            }

            LabResponse response = JsonConvert.DeserializeObject <LabResponse>(result);
            LabUser     user     = JsonConvert.DeserializeObject <LabUser>(result);

            if (!string.IsNullOrEmpty(user.HomeTenantId) && !string.IsNullOrEmpty(user.HomeUPN))
            {
                user.InitializeHomeUser();
            }

            return(response);
        }
        public void InitializeHomeUser()
        {
            HomeUser = new LabUser();
            var labHomeUser = (LabUser)HomeUser;

            labHomeUser.ObjectId           = ObjectId;
            labHomeUser.UserType           = UserType;
            labHomeUser.CredentialUrl      = CredentialUrl;
            labHomeUser.HomeUser           = labHomeUser;
            labHomeUser.IsExternal         = IsExternal;
            labHomeUser.IsMfa              = IsMfa;
            labHomeUser.IsMam              = IsMam;
            labHomeUser.Licenses           = Licenses;
            labHomeUser.IsFederated        = IsFederated;
            labHomeUser.FederationProvider = FederationProvider;
            labHomeUser.HomeTenantId       = HomeTenantId;
            labHomeUser.HomeUPN            = HomeUPN;
            labHomeUser.CurrentTenantId    = HomeTenantId;
            labHomeUser.Upn = HomeUPN;
            labHomeUser.B2CIdentityProvider = B2CIdentityProvider;
        }
        public static string GetUserPassword(LabUser user)
        {
            if (string.IsNullOrWhiteSpace(user.CredentialUrl))
            {
                throw new InvalidOperationException("Error: CredentialUrl is not set on user. Password retrieval failed.");
            }

            if (_keyVaultSecretsProvider == null)
            {
                throw new InvalidOperationException("Error: Keyvault secrets provider is not set");
            }

            try
            {
                var secret = _keyVaultSecretsProvider.GetSecret(user.CredentialUrl);
                return(secret.Value);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Test setup: cannot get the user password. See inner exception.", e);
            }
        }
        private LabResponse GetLabResponseFromAPI(UserQueryParameters query)
        {
            HttpClient webClient = new HttpClient();
            IDictionary <string, string> queryDict = new Dictionary <string, string>
            {
                // Disabled for now until there are tests that use it.
                { "mamca", "false" },
                { "mdmca", "false" }
            };

            //Building user query
            if (query.FederationProvider != null)
            {
                queryDict.Add("federationProvider", query.FederationProvider.ToString());
            }

            queryDict.Add("mam", query.IsMamUser.HasValue && query.IsMamUser.Value ? "true" : "false");
            queryDict.Add("mfa", query.IsMfaUser.HasValue && query.IsMfaUser.Value ? "true" : "false");

            if (query.Licenses != null && query.Licenses.Count > 0)
            {
                queryDict.Add("license", query.Licenses.ToArray().ToString());
            }

            queryDict.Add("isFederated", query.IsFederatedUser.HasValue && query.IsFederatedUser.Value ? "true" : "false");

            if (query.UserType != null)
            {
                queryDict.Add("usertype", query.UserType.ToString());
            }

            queryDict.Add("external", query.IsExternalUser.HasValue && query.IsExternalUser.Value ? "true" : "false");

            if (query.B2CIdentityProvider == B2CIdentityProvider.Local)
            {
                queryDict.Add("b2cProvider", "local");
            }

            if (query.B2CIdentityProvider == B2CIdentityProvider.Facebook)
            {
                queryDict.Add("b2cProvider", "facebook");
            }

            if (query.B2CIdentityProvider == B2CIdentityProvider.Google)
            {
                queryDict.Add("b2cProvider", "google");
            }

            UriBuilder uriBuilder = new UriBuilder("http://api.msidlab.com/api/user")
            {
                Query = string.Join("&", queryDict.Select(x => x.Key + "=" + x.Value.ToString()))
            };

            //Fetch user
            string result = webClient.GetStringAsync(uriBuilder.ToString()).GetAwaiter().GetResult();

            if (string.IsNullOrWhiteSpace(result))
            {
                throw new LabUserNotFoundException(query, "No lab user with specified parameters exists");
            }

            LabUser user = JsonConvert.DeserializeObject <LabUser>(result);

            if (!string.IsNullOrEmpty(user.HomeTenantId) && !string.IsNullOrEmpty(user.HomeUPN))
            {
                user.InitializeHomeUser();
            }

            return(JsonConvert.DeserializeObject <LabResponse>(result));;
        }