Пример #1
0
        public void RegularKey()
        {
            //Regular key
            var headers = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("apiKey", Properties.Settings.Default.apiKey)
            };

            InitializeContext(headers, false);
            var attr = new OnlyAuthorizedAttribute();

            attr.OnAuthorization(actionContext);
            Assert.IsNull(actionContext.Response);
        }
Пример #2
0
        public void Anonymous()
        {
            //Regular key
            var headers = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("apiKey", "XXX")
            };

            InitializeContext(headers, true);
            var attr = new OnlyAuthorizedAttribute();

            attr.OnAuthorization(actionContext);
            Assert.IsNull(actionContext.Response);
        }
Пример #3
0
        public void FakeKey()
        {
            //First fake key
            var headers = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("apiKey", "XXX")
            };

            InitializeContext(headers, false);

            var attr = new OnlyAuthorizedAttribute();

            attr.OnAuthorization(actionContext);
            Assert.AreEqual(HttpStatusCode.Unauthorized, actionContext.Response.StatusCode);
        }