Exemplo n.º 1
0
        //---------------------------------------------------------------------
        // Constructs request to MR.
        //---------------------------------------------------------------------
        public static BlobsRequest MRR(Workspace w, SerializationFormatKind format, RequestVerb verb, string payload, HttpStatusCode expectedStatusCode, params string[] URI)
        {
            string       uri = URI.Length == 0 ? LastURI : URI[0];
            BlobsRequest rq  = new BlobsRequest(w, format, verb, uri, expectedStatusCode);

            // Specific request properties.
            rq.Format      = SerializationFormatKind.PlainText;
            rq.ContentType = "audio/mp3";
            rq.Accept      = (verb == RequestVerb.Get ? "*/*" : SerializationFormatKinds.ContentTypeFromKind(format));
            rq.Payload     = payload;

            // Append $value, if needed.
            if (uri.StartsWith("$") || uri.EndsWith(")"))
            {
                rq.URI += "/$value";

                // Expect dummy ETags from stream provider.
                byte[] hash = new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(System.Text.Encoding.ASCII.GetBytes(rq.URI));
                if ((hash[0] & 3) > 1)
                {
                    rq.ETagHeaderExpected = true;
                }
            }

            return(rq);
        }
Exemplo n.º 2
0
        //---------------------------------------------------------------------
        // Sends and verifies request for all possible access rights.
        //---------------------------------------------------------------------
        public void TestAccess(string container)
        {
            // Save current state.
            HttpStatusCode normalStatusCode = ExpectedStatusCode;

#if !ClientSKUFramework
            for (uint i = 0; i <= (uint)Microsoft.OData.Service.EntitySetRights.All; i++)
            {
                // Set entity set access right.
                Workspace.DataService.ConfigSettings.SetEntitySetAccessRule(container, (Microsoft.OData.Service.EntitySetRights)i);

                // Calculate minimum access needed for request to succeed.
                Microsoft.OData.Service.EntitySetRights minAccess = Microsoft.OData.Service.EntitySetRights.All;
                switch (Verb)
                {
                case RequestVerb.Post: minAccess = Microsoft.OData.Service.EntitySetRights.WriteAppend; break;

                case RequestVerb.Get: minAccess = Microsoft.OData.Service.EntitySetRights.ReadSingle; break;

                case RequestVerb.Put: minAccess = Microsoft.OData.Service.EntitySetRights.WriteReplace | Microsoft.OData.Service.EntitySetRights.ReadSingle; break;

                case RequestVerb.Patch: minAccess = Microsoft.OData.Service.EntitySetRights.WriteMerge | Microsoft.OData.Service.EntitySetRights.ReadSingle; break;

                case RequestVerb.Delete: minAccess = Microsoft.OData.Service.EntitySetRights.WriteDelete | Microsoft.OData.Service.EntitySetRights.ReadSingle; break;

                default:
                    AstoriaTestLog.FailAndThrow("Test issue - unknown request verb (2)");
                    break;
                }

                // Calculate expected status code.
                ExpectedStatusCode =
                    i == 0 ? HttpStatusCode.NotFound
                    : (i & (uint)minAccess) == (uint)minAccess ? normalStatusCode : HttpStatusCode.Forbidden;

                // Send and verify request.
                AstoriaResponse response = SendAndVerify(null);

                // Delete the entity if it was created to avoid "key already exists" collisions.
                if (response.Headers.ContainsKey("Location"))
                {
                    string newEntity = response.Headers["Location"];

                    Workspace.DataService.ConfigSettings.SetEntitySetAccessRule(container, Microsoft.OData.Service.EntitySetRights.WriteDelete | Microsoft.OData.Service.EntitySetRights.ReadSingle);


                    BlobsRequest.MLE(Workspace, Format, RequestVerb.Delete, null, HttpStatusCode.NoContent, newEntity).SendAndVerify(null);
                }
            }
#endif


            // Restore previous state.
            ExpectedStatusCode = normalStatusCode;
#if !ClientSKUFramework
            Workspace.DataService.ConfigSettings.SetEntitySetAccessRule(container, Microsoft.OData.Service.EntitySetRights.All);
#endif
        }
Exemplo n.º 3
0
        //---------------------------------------------------------------------
        // Constructs request to MLE.
        //---------------------------------------------------------------------
        public static BlobsRequest MLE(Workspace w, SerializationFormatKind format, RequestVerb verb, BlobsPayload payload, HttpStatusCode expectedStatusCode, params string[] URI)
        {
            string       uri = URI.Length == 0 ? LastURI : URI[0];
            BlobsRequest rq  = new BlobsRequest(w, format, verb, uri, expectedStatusCode);

            // Specific request properties.
            rq.Format      = format;
            rq.ContentType = SerializationFormatKinds.ContentTypeFromKind(format);
            rq.Accept      = rq.ContentType;
            rq.Payload     = (payload != null ? payload.ToString() : null);

            return(rq);
        }
Exemplo n.º 4
0
        //---------------------------------------------------------------------
        // Constructs request to MLE.
        //---------------------------------------------------------------------
        public static BlobsRequest MLE(Workspace w, SerializationFormatKind format, RequestVerb verb, BlobsPayload payload, HttpStatusCode expectedStatusCode, params string[] URI)
        {
            string uri = URI.Length == 0 ? LastURI : URI[0];
            BlobsRequest rq = new BlobsRequest(w, format, verb, uri, expectedStatusCode);

            // Specific request properties.
            rq.Format = format;
            rq.ContentType = SerializationFormatKinds.ContentTypeFromKind(format);
            rq.Accept = rq.ContentType;
            rq.Payload = (payload != null ? payload.ToString() : null);

            return rq;
        }
Exemplo n.º 5
0
        //---------------------------------------------------------------------
        // Constructs request with $ref. Assumes parent(*)/child URI format.
        //---------------------------------------------------------------------
        public static BlobsRequest LNK(Workspace w, SerializationFormatKind format, RequestVerb verb, string payload, HttpStatusCode expectedStatusCode, params string[] URI)
        {
            string       uri = (URI.Length == 0 ? LastURI : URI[0]);
            BlobsRequest rq  = new BlobsRequest(w, format, verb, uri, expectedStatusCode);

            // Specific request properties.
            rq.Format      = format;
            rq.ContentType = SerializationFormatKinds.ContentTypeFromKind(format == SerializationFormatKind.JSON ? SerializationFormatKind.JSON : SerializationFormatKind.PlainXml);
            rq.Accept      = rq.ContentType;

            // Adjust link in payload, if needed.
            if (!string.IsNullOrEmpty(payload))
            {
                rq.Payload = string.Format(format == SerializationFormatKind.JSON ?
                                           @"{{""odata.id"": ""{0}"" }}" :
                                           @"<ref xmlns='http://docs.oasis-open.org/odata/ns/metadata' id=""{0}"" />",
                                           payload);
            }

            return(rq);
        }
Exemplo n.º 6
0
        //---------------------------------------------------------------------
        // Constructs request to MR.
        //---------------------------------------------------------------------
        public static BlobsRequest MRR(Workspace w, SerializationFormatKind format, RequestVerb verb, string payload, HttpStatusCode expectedStatusCode, params string[] URI)
        {
            string uri = URI.Length == 0 ? LastURI : URI[0];
            BlobsRequest rq = new BlobsRequest(w, format, verb, uri, expectedStatusCode);

            // Specific request properties.
            rq.Format = SerializationFormatKind.PlainText;
            rq.ContentType = "audio/mp3";
            rq.Accept = (verb == RequestVerb.Get ? "*/*" : SerializationFormatKinds.ContentTypeFromKind(format));
            rq.Payload = payload;

            // Append $value, if needed.
            if (uri.StartsWith("$") || uri.EndsWith(")"))
            {
                rq.URI += "/$value";

                // Expect dummy ETags from stream provider.
                byte[] hash = new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(System.Text.Encoding.ASCII.GetBytes(rq.URI));
                if ((hash[0] & 3) > 1)
                    rq.ETagHeaderExpected = true;
            }

            return rq;
        }
Exemplo n.º 7
0
        //---------------------------------------------------------------------
        // Constructs request with $ref. Assumes parent(*)/child URI format.
        //---------------------------------------------------------------------
        public static BlobsRequest LNK(Workspace w, SerializationFormatKind format, RequestVerb verb, string payload, HttpStatusCode expectedStatusCode, params string[] URI)
        {
            string uri = (URI.Length == 0 ? LastURI : URI[0]);
            BlobsRequest rq = new BlobsRequest(w, format, verb, uri, expectedStatusCode);

            // Specific request properties.
            rq.Format = format;
            rq.ContentType = SerializationFormatKinds.ContentTypeFromKind(format == SerializationFormatKind.JSON ? SerializationFormatKind.JSON : SerializationFormatKind.PlainXml);
            rq.Accept = rq.ContentType;
            
            // Adjust link in payload, if needed.
            if (!string.IsNullOrEmpty(payload))
            {
                rq.Payload = string.Format(format == SerializationFormatKind.JSON ?
                    @"{{""odata.id"": ""{0}"" }}" :
                    @"<ref xmlns='http://docs.oasis-open.org/odata/ns/metadata' id=""{0}"" />",
                    payload);
            }

            return rq;
        }