示例#1
0
        private bool connectInternal(string url, string userName, bool refreshCachedMetaData, out string errorMessage, out bool invalidUserName)
        {
            if (wsAPI == null)
            {
                wsAPI = new WebServiceAPIWrapper();
                onChannelStateChanged(WebServiceChannelState.Created);
                subscribeChannelEvents();
            }
            bool succeeded = wsAPI.Connect(url, userName, out errorMessage, out invalidUserName);

            if (succeeded == false)
            {
                return(false);
            }

            // conditionally update the cache metadata
            if (refreshCachedMetaData == true)
            {
                NoteTypeInfo[] noteTypes = wsAPI.GetAllNoteTypes();
                this.Cache.MetaData.AssignNoteTypes(noteTypes);

                UserInfo[] users = wsAPI.GetAllUsers();
                this.Cache.MetaData.AssignUsers(users);

                this.Cache.SaveMetaData();
            }

            return(true);
        }
示例#2
0
 public void Reconnect()
 {
     Disconnect();
     if (string.IsNullOrEmpty(this.lastConnectionUrl) == false)
     {
         string notUsed;
         bool   invalidUserName;
         bool   connected = connectInternal(lastConnectionUrl, this.userName, false, out notUsed, out invalidUserName);
         if (connected == false)
         {
             wsAPI = null;
         }
     }
 }
示例#3
0
 public void Disconnect()
 {
     assertInitialized();
     if (wsAPI != null)
     {
         try
         {
             wsAPI.Disconnect();
         }
         catch
         {
         }
         finally
         {
             unsubscribeChannelEvents();
             wsAPI = null;
         }
     }
 }
        public static bool TestAccessTokenEnforcement(string serviceURL, string cachePath, string validUserName, string invalidUserName, bool isValidUser, out string errorMessage)
        {
            errorMessage = null;
            CFIClient client = new CFIClient();

            client.Initialize(cachePath);
            // we use the valid user name only for the channel connection
            bool userNameWasInvalid;

            if (client.Connect(serviceURL, validUserName, false, out errorMessage, out userNameWasInvalid) == false)
            {
                return(false);
            }
            client.DebugSetUserName(invalidUserName);



            MethodInfo[] methods = typeof(JobInspectionClient).GetMethods(BindingFlags.Instance | BindingFlags.Public);
            foreach (MethodInfo method in methods)
            {
                if (method.DeclaringType.Namespace == "CFI.Client.JobInspectionService")
                {
                    try
                    {
                        List <object> arguments = new List <object>();
                        int           i         = 0;
                        foreach (ParameterInfo parameter in method.GetParameters())
                        {
                            if (i == 0)
                            {
                                if (isValidUser == true)
                                {
                                    // the wrapper API would generate a token this way
                                    arguments.Add(SecurityUtils.CreateAccessToken(validUserName));
                                }
                                else
                                {
                                    // a rogue user or someone using the app without knowing a proper username would generate an invalid token
                                    // (that's the idea anyway...). So we just tokenize a bogus 'guessed' username for this test
                                    arguments.Add(SecurityUtils.CreateAccessToken(invalidUserName));
                                }
                            }
                            else
                            {
                                if (parameter.ParameterType.IsClass)
                                {
                                    arguments.Add(null);
                                }
                                else if (isNumericType(parameter.ParameterType) == true)
                                {
                                    arguments.Add(0);
                                }
                                else if (parameter.ParameterType.Name == "Boolean")
                                {
                                    arguments.Add(false);
                                }
                                else
                                {
                                    errorMessage = "Unhandled parameter type in unit test code.  Need to add this type to the handler.";
                                    return(false);
                                }
                            }
                            i++;
                        }
                        method.Invoke(client.WebServiceAPI.ServiceClient, arguments.ToArray());
                    }
                    catch (Exception ex)
                    {
                        InvalidUserException iuex = WebServiceAPIWrapper.TranslateException(ex) as InvalidUserException;
                        if (iuex != null)
                        {
                            // we expect this exception sometimes so check to see if this is one of those times
                            if (isValidUser == true)
                            {
                                // we said it was an valid user so this is NOT expected
                                errorMessage = string.Format("unexpected access token exception in test method '{0}.'\r\n{1}", method.Name, iuex.Message);
                                return(false);
                            }
                            else
                            {
                                // we said it was an invalid user so this IS expected
                                return(true);
                            }
                        }
                        else
                        {
                            errorMessage = string.Format("unexpected exception in test method '{0}'\r\n{1}\r\n{2}", method.Name, ex.Message, ex.StackTrace);
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }