Esempio n. 1
0
 /// <summary>
 /// A method is used to check whether the WOPI server Cobalt feature, this feature depends on that the WOPI server whether implements MS-FSSHTTP. If current WOPI server does support Cobalt feature, this method will capture related requirement R961, otherwise this method will raise an inconclusive assertion.
 /// </summary>
 /// <param name="siteInstance">A parameter represents the site instance.</param>
 public static void PerformSupportCobaltCheck(ITestSite siteInstance)
 {
     DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <ITestSite>(siteInstance, "siteInstance", "PerformSupportCobaltCheck");
     if (!Common.IsRequirementEnabled("MS-WOPI", 961, siteInstance))
     {
         siteInstance.Assert.Inconclusive(@"The WOPI server does not support the Cobalt feature. To supporting this feature, the WOPI server must implement the MS-FSSHTTP protocol.It is determined by ""R961Enabled_MS-WOPI"" SHOULDMAY property.");
     }
 }
Esempio n. 2
0
        /// <summary>
        /// A method is used to get a xml string from a WOPI Discovery type object. The xml string is used to response the discovery request.
        /// </summary>
        /// <param name="discoveryObject">A parameter represents the WOPI Discovery object which contain the discovery information.</param>
        /// <returns>A parameter represents the xml string which contains the discovery information.</returns>
        public static string GetDiscoveryXmlFromDiscoveryObject(wopidiscovery discoveryObject)
        {
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <wopidiscovery>(discoveryObject, "discoveryObject", "GetDiscoveryXmlFromDiscoveryObject");

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(wopidiscovery));
            string        xmlString     = string.Empty;

            MemoryStream memorySteam = null;

            try
            {
                memorySteam = new MemoryStream();
                StreamWriter streamWriter = null;
                try
                {
                    streamWriter = new StreamWriter(memorySteam, Encoding.UTF8);

                    // Remove w3c default namespace prefix in serialize process.
                    XmlSerializerNamespaces nameSpaceInstance = new XmlSerializerNamespaces();
                    nameSpaceInstance.Add(string.Empty, string.Empty);
                    xmlSerializer.Serialize(streamWriter, discoveryObject, nameSpaceInstance);

                    // Read the MemoryStream to output the xml string.
                    memorySteam.Position = 0;
                    using (StreamReader streamReader = new StreamReader(memorySteam))
                    {
                        xmlString = streamReader.ReadToEnd();
                    }
                }
                finally
                {
                    if (streamWriter != null)
                    {
                        streamWriter.Dispose();
                    }
                }
            }
            finally
            {
                if (memorySteam != null)
                {
                    memorySteam.Dispose();
                }
            }

            if (string.IsNullOrEmpty(xmlString))
            {
                throw new InvalidOperationException("Could not get the xml string.");
            }

            // Format the serialized xml string.
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xmlString);
            return(xmlDoc.OuterXml);
        }
Esempio n. 3
0
        /// <summary>
        /// A method is used to start listening the discovery request from the WOPI server. If the listen thread has existed, the DiscoverProcessHelper will not start any new listen thread.
        /// </summary>
        /// <param name="currentTestClient">A parameter represent the current test client which acts as WOPI client to listen the discovery request.</param>
        /// <param name="progId">A parameter represents the id of program which is associated with folder level visit in discovery process. This value must be valid for WOPI server. For Microsoft products, this value can be "OneNote.Notebook". It is used to ensure the WOPI server can support folder level visit ability in WOPI mode when receive the value from the discovery response.</param>
        public static void StartDiscoveryListen(string currentTestClient, string progId)
        {
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <string>(currentTestClient, "currentTestClient", "StartDiscoveryListen");
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <string>(progId, "progId", "StartDiscoveryListen");

            if (null == discoveryListenerInstance)
            {
                string discoveryXmlResponse = GetDiscoveryResponseXmlString(currentTestClient, progId);
                discoveryListenerInstance = new DiscoveryRequestListener(currentTestClient, discoveryXmlResponse);
                discoveryListenerInstance.StartListen();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// This method is used to convert the XML date to the Discovery object.
        /// </summary>
        /// <param name="xmlValue">The value of the xml string.</param>
        /// <returns>The object value which is converted from the xml string.</returns>
        public static wopidiscovery DeserializeXmlToDiscoveryObject(string xmlValue)
        {
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <string>(xmlValue, "xmlString", "DeserializeXmlToDiscoveryObject");

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(wopidiscovery));
            wopidiscovery discovery     = null;

            using (StringReader strReader = new StringReader(xmlValue))
            {
                discovery = xmlSerializer.Deserialize(strReader) as wopidiscovery;
                if (null == discovery)
                {
                    throw new ArgumentNullException("discovery", "Could not get the current xml string to the expected Discovery type.");
                }
            }

            return(discovery);
        }
Esempio n. 5
0
        /// <summary>
        /// A method is used to perform the discovery process
        /// </summary>
        /// <param name="currentTestClient">A parameter represents the current test client which is listening the discovery request.</param>
        /// <param name="sutControllerAdapterInstance">A parameter represents the IMS_WOPISUTControlAdapter instance which is used to make the WOPI server perform sending discovery request to the discovery listener.</param>
        /// <param name="siteInstance">A parameter represents the ITestSite instance which is used to get the test context.</param>
        public static void PerformDiscoveryProcess(string currentTestClient, IMS_WOPISUTControlAdapter sutControllerAdapterInstance, ITestSite siteInstance)
        {
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <string>(currentTestClient, "currentTestClient", "PerformDiscoveryProcess");
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <IMS_WOPISUTControlAdapter>(sutControllerAdapterInstance, "sutControllerAdapterInstance", "PerformDiscoveryProcess");
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <ITestSite>(siteInstance, "siteInstance", "PerformDiscoveryProcess");

            // If the test class invoke this, means the test class will uses the WOPI discovery binding. The test suite will count all WOPI discovery usage of test classes
            System.Threading.Interlocked.Increment(ref cleanUpDiscoveryStatusCounter);

            // Start the listener, if the listen thread has been start, the DiscoverProcessHelper will not start any new listen thread.
            DiscoveryProcessHelper.StartDiscoveryListen(currentTestClient, progId);

            // Initialize the WOPI Discovery process so that the WOPI server will use the test suite as WOPI client.
            if (!DiscoveryProcessHelper.HasPerformDiscoveryProcessSucceed)
            {
                DiscoveryProcessHelper.PerformDiscoveryProcess(currentTestClient, sutControllerAdapterInstance);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// A method is used to generate response of a WOPI discovery request. It indicates the WOPI client supports 3 types file extensions: ".txt", ".zip", ".one"
        /// </summary>
        /// <param name="currentTestClientName">A parameter represents the current test client name which is used to construct WOPI client's app name in WOPI discovery response.</param>
        /// <param name="progId">A parameter represents the id of program which is associated with folder level visit in discovery process. This value must be valid for WOPI server.</param>
        /// <returns>A return value represents the response of a WOPI discovery request.</returns>
        public static string GetDiscoveryResponseXmlString(string currentTestClientName, string progId)
        {
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <string>(currentTestClientName, "currentTestClientName", "GetDiscoveryResponseXmlString");
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <string>(progId, "progId", "GetDiscoveryResponseXmlString");

            wopidiscovery wopiDiscoveryInstance = new wopidiscovery();

            // Pass the prog id, so that the WOPI discovery response logic will use the prog id value.
            progIdValue = progId;

            // Add http and https net zone into the wopiDiscovery
            wopiDiscoveryInstance.netzone = GetNetZonesForWopiDiscoveryResponse(currentTestClientName);

            // ProofKey element
            wopiDiscoveryInstance.proofkey          = new ct_proofkey();
            wopiDiscoveryInstance.proofkey.oldvalue = RSACryptoContext.PublicKeyStringOfOld;
            wopiDiscoveryInstance.proofkey.value    = RSACryptoContext.PublicKeyStringOfCurrent;
            string xmlStringOfResponseDiscovery = WOPISerializerHelper.GetDiscoveryXmlFromDiscoveryObject(wopiDiscoveryInstance);

            return(xmlStringOfResponseDiscovery);
        }
Esempio n. 7
0
        /// <summary>
        /// A method is used to clean up the WOPI discovery record for the WOPI server. For removing the record successfully, the WOPI server can be triggered the WOPI discovery process again.
        /// </summary>
        /// <param name="wopiClientName">A parameter represents the WOPI client name which should have been discovered by WOPI server</param>
        /// <param name="sutControllerInstance">A parameter represents the IMS_WOPISUTControlAdapter instance which is used to make the WOPI server clean up discovery record for the specified WOPI client.</param>
        public static void CleanUpDiscoveryRecord(string wopiClientName, IMS_WOPISUTControlAdapter sutControllerInstance)
        {
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <IMS_WOPISUTControlAdapter>(sutControllerInstance, "sutControllerInstance", "CleanUpDiscoveryRecord");

            if (!NeedToCleanUpDiscoveryRecord)
            {
                return;
            }

            lock (lockObjectOfVisitDiscoveryProcessStatus)
            {
                if (hasPerformDiscoveryProcessSucceed && !hasPerformCleanUpForDiscovery)
                {
                    bool isDiscoveryRecordRemoveSuccessful = sutControllerInstance.RemoveWOPIDiscoveryRecord(wopiClientName);
                    if (!isDiscoveryRecordRemoveSuccessful)
                    {
                        throw new InvalidOperationException("Could not remove the discovery record successfully, need to remove that manually.");
                    }

                    hasPerformCleanUpForDiscovery = true;
                }
            }
        }