protected void OKButton_Click(object sender, EventArgs e)
        {
            SubscriberTableAdapter sta = new SubscriberTableAdapter();
            DataSet.SubscriberDataTable dt = sta.GetDataByAuthKey(AuthenticationKeyTextBox.Text);
            if (dt.Count == 0)
            {
                InvalidKeyLabel.Text = "���͂��ꂽ�F�؃L�[�͖����ł��B";
                return;
            }
            DataSet.SubscriberRow subscriber = dt[0];
            TokenPublisher p = new TokenPublisher(subscriber, DateTime.Now);
            DataSet.TokenRow token;
            try
            {
                token = p.Publish();
            }
            catch (DoubtfulAuthBehaviorException ex)
            {
                p.LockOut();
                logger.Info(ex.Message);
                WebUtil.RedirectToLockout(Context, subscriber.LockoutUntil);
                return;
            }
            WebUtil.AddAuthCookie(Response, token.Body);

            if (Request.QueryString["from"] != null && Request.QueryString["from"].Length > 0)
            {
                Response.Redirect(HttpUtility.UrlDecode(Request.QueryString["from"]));
            }
        }
        public void Test_Process_BadDeviceToken()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                DataSet.TitleRow title = PrepareBasic();

                RequestProcessor rp = new RequestProcessor();
                try
                {
                    rp.Process("malformeddevicetokenmalformeddevicetokenmalformeddevicetokenmalf");
                    Expect(false);
                }
                catch (BadDeviceTokenException)
                {
                    // OK
                }

                APNsTableAdapter ata = new APNsTableAdapter();
                DataSet.APNsDataTable adt = ata.GetDataByTitleId(title.Id);
                Expect(adt.Count, Is.EqualTo(0));

                SubscriberTableAdapter sta = new SubscriberTableAdapter();
                DataSet.SubscriberDataTable sdt = sta.GetDataByTitleId(title.Id);
                Expect(sdt.Count, Is.EqualTo(0));
            }
        }
Пример #3
0
        public void Test_Properties()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                TitleTableAdapter tta = new TitleTableAdapter();
                tta.Insert("test title", "test push message", basePath + @"\copyDirectory_dist", basePath + @"\copyDirectory_orig");
                DataSet.TitleRow title = tta.GetDataByName("test title")[0];

                SubscriberTableAdapter sta = new SubscriberTableAdapter();
                sta.Insert(title.Id, "test authkey", "web", Constant.Ago);
                sta.Insert(title.Id, "test authkey 2", "web", new DateTime(2011, 10, 13));
                DataSet.SubscriberDataTable sdt = sta.GetDataByTitleId(title.Id);
                DataSet.SubscriberRow s1, s2;
                if (sdt[0].AuthenticationKey == "test authkey")
                {
                    s1 = sdt[0];
                    s2 = sdt[1];
                }
                else
                {
                    s2 = sdt[0];
                    s1 = sdt[1];
                }

                TokenTableAdapter kta = new TokenTableAdapter();
                kta.Insert(s1.Id, new DateTime(2011, 10, 12, 0, 0, 0), "deadbeef");
                kta.Insert(s2.Id, new DateTime(2011, 10, 12, 4, 59, 50), "deadbeef2");
                DataSet.TokenRow k1, k2;
                k1 = kta.GetDataByBody("deadbeef")[0];
                k2 = kta.GetDataByBody("deadbeef2")[0];

                Expect(SiteConstant.IsConfigurationOK, Is.EqualTo(true));

                DateTime now = new DateTime(2011, 10, 12, 5, 0, 0);

                TokenPublisher p1 = new TokenPublisher(s1, now);
                DataSet.TokenRow pk1 = p1.Publish();
                Expect(pk1.Id, Is.Not.EqualTo(k1.Id));

                TokenPublisher p2 = new TokenPublisher(s2, now);
                DataSet.TokenRow pk2 = p2.Publish();
                Expect(pk2.Id, Is.EqualTo(k2.Id));

                kta.Insert(s2.Id, new DateTime(2011, 10, 12, 4, 59, 10), "deadbeef3");
                kta.Insert(s2.Id, new DateTime(2011, 10, 12, 4, 59, 20), "deadbeef4");

                TokenPublisher p2_2 = new TokenPublisher(s2, now);
                try
                {
                    p2_2.Publish();
                    Expect(false);
                }
                catch (DoubtfulAuthBehaviorException)
                {
                    // OK
                }
                Expect(kta.GetDataBySubscriberId(s2.Id).Count, Is.EqualTo(3));
            }
        }
Пример #4
0
 public static DataSet.SubscriberRow PublishSubscriber(AuthScheme authScheme)
 {
     DataSet.SubscriberDataTable dt = new DataSet.SubscriberDataTable();
     SubscriberTableAdapter ta = new SubscriberTableAdapter();
     dt.AddSubscriberRow(SiteConstant.Title, Guid.NewGuid().ToString("N"), authScheme.ToString(), Constant.Ago);
     ta.Update(dt);
     return dt[0];
 }
Пример #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     TitleTableAdapter tta = new TitleTableAdapter();
     DataSet.TitleRow title = tta.GetDataByName("debug title")[0];
     SubscriberTableAdapter sta = new SubscriberTableAdapter();
     DataSet.SubscriberDataTable sdt = sta.GetDataByTitleId(title.Id);
     if (sdt.Count == 0)
     {
         sdt.AddSubscriberRow(title, "debug auth key", AuthScheme.Web.ToString(), Constant.Ago);
         sta.Update(sdt);
     }
     subscriber = sdt[0];
 }
Пример #6
0
        protected void CleanUpButton_Click(object sender, EventArgs e)
        {
            DataSet.TokenDataTable dt = ta.GetData();
            foreach (DataSet.TokenRow r in dt)
            {
                r.Delete();
            }
            ta.Update(dt);

            SubscriberTableAdapter sta = new SubscriberTableAdapter();
            dt.AddTokenRow(subscriber, new DateTime(2000, 1, 1), "debugdeadbeef");
            ta.Update(dt);
            subscriber.LockoutUntil = Constant.Ago;
            sta.Update(subscriber);
        }
Пример #7
0
        public TokenVerifier(DataSet.TokenRow token, DateTime now)
        {
            this.now = now;
            if (token == null)
            {
                subscriber = null;
                return;
            }

            this.token = token;
            SubscriberTableAdapter sta = new SubscriberTableAdapter();
            DataSet.SubscriberDataTable sdt = sta.GetDataById(token.SubscriberId);
            subscriber = sdt[0];
            if (subscriber.TitleId != SiteConstant.Title.Id)
            {
                subscriber = null;
            }
        }
Пример #8
0
 public static DataSet.SubscriberRow ResolveSubscriber(string tokenBody, AuthScheme authScheme)
 {
     if (tokenBody == null)
     {
         return PublishSubscriber(authScheme);
     }
     TokenTableAdapter tta = new TokenTableAdapter();
     DataSet.TokenDataTable tdt = tta.GetDataByBody(tokenBody);
     if (tdt.Count == 0)
     {
         return PublishSubscriber(authScheme);
     }
     DataSet.TokenRow token = tdt[0];
     SubscriberTableAdapter sta = new SubscriberTableAdapter();
     DataSet.SubscriberRow subscriber = sta.GetDataById(token.SubscriberId)[0];
     if (subscriber.AuthScheme != authScheme.ToString())
     {
         throw new DoubtfulAuthBehaviorException("�F�؃g�[�N�������s���ꂽ�Ƃ��Ƃ͈قȂ�F�ؕ����œn����܂����B");
     }
     return subscriber;
 }
Пример #9
0
        public void TestNotification()
        {
            logger.Info("test");
            //            Settings.TestSettings(typeof(NotificationServiceStub), null);
            using (TransactionScope scope = new TransactionScope())
            {
                TitleTableAdapter tta = new TitleTableAdapter();
                DataSet.TitleDataTable tdt = new DataSet.TitleDataTable();
                tdt.AddTitleRow("test title", "test push message", "test site root path", "test standby path");
                tta.Update(tdt);
                DataSet.TitleRow title = tdt[0];

                CredentialTableAdapter cta = new CredentialTableAdapter();
                DataSet.CredentialDataTable cdt = new DataSet.CredentialDataTable();
                cdt.AddCredentialRow(title, Credential.ApnsPkcs12FilePathKind, SecureConstant.P12File);
                cta.Update(cdt);
                cdt.AddCredentialRow(title, Credential.ApnsPkcs12FilePasswordKind, SecureConstant.P12FilePassword);
                cta.Update(cdt);
                cdt.AddCredentialRow(title, Credential.LvlRsaKeyValueKind, "test lvlrsakeyvalue");
                cta.Update(cdt);

                SubscriberTableAdapter sta = new SubscriberTableAdapter();
                DataSet.SubscriberDataTable sdt = new DataSet.SubscriberDataTable();
                sdt.AddSubscriberRow(title, "test authkey", "web", Constant.Ago);
                sta.Update(sdt);
                DataSet.SubscriberRow subscriber = sdt[0];

                APNsTableAdapter ata = new APNsTableAdapter();
                ata.Insert(subscriber.Id, "B9C83DAE377DDEEECB7C9EA662F7BFBC5D3FA95A5AD5E3CD4B0DD843E0D9EBED", false, 0, false);

                ApnsPusher p = ApnsPusher.GetInstance(title);
                p.PushReleaseNotification("test push message 2");
                System.Threading.Thread.Sleep(10000); // �����ɏI������ƒʐM���Ԃɍ���Ȃ��i���ۂɑ��M����ꍇ�j

                DataSet.APNsDataTable adt = ata.GetDataByTitleId(title.Id);
                Expect(adt[0].UnreadRelease, Is.EqualTo(1));
            }
        }
Пример #10
0
        public void Test_ApnsFeedback()
        {
            Settings.TestSettings(null, typeof(FeedbackServiceStub));
            using (TransactionScope scope = new TransactionScope())
            {
                TitleTableAdapter tta = new TitleTableAdapter();
                tta.Insert("test title", "test push message", "test site root path", "test standby path");
                DataSet.TitleRow title = tta.GetDataByName("test title")[0];

                SubscriberTableAdapter sta = new SubscriberTableAdapter();
                sta.Insert(title.Id, "test authkey", "web", Constant.Ago);
                DataSet.SubscriberRow subscriber = sta.GetDataByTitleId(title.Id)[0];

                APNsTableAdapter ata = new APNsTableAdapter();
                ata.Insert(subscriber.Id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", false, 0, false);

                ApnsFeedback fb = new ApnsFeedback(title);
                fb.Run();

                DataSet.APNsDataTable adt = ata.GetDataByTitleId(title.Id);
                Expect(adt[0].Failed, Is.EqualTo(true));
            }
        }
        private DataSet.SubscriberRow PrepareExist(DataSet.TitleRow title)
        {
            SubscriberTableAdapter sta = new SubscriberTableAdapter();
            DataSet.SubscriberDataTable sdt = new DataSet.SubscriberDataTable();
            sdt.AddSubscriberRow(title, "deadbeef", AuthScheme.iOS_APNs.ToString(), Constant.Ago);
            sta.Update(sdt);
            DataSet.SubscriberRow subscriber = sdt[0];

            APNsTableAdapter ata = new APNsTableAdapter();
            DataSet.APNsDataTable adt = new DataSet.APNsDataTable();
            adt.AddAPNsRow(subscriber, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", false, 0, false);
            ata.Update(adt);

            TokenTableAdapter tta = new TokenTableAdapter();
            DataSet.TokenDataTable tdt = new DataSet.TokenDataTable();
            tdt.AddTokenRow(subscriber, DateTime.Now - new TimeSpan(48, 0, 0), "deadbeef");
            tta.Update(tdt);

            return subscriber;
        }
        public void Test_Process_NewSubscriber()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                DataSet.TitleRow title = PrepareBasic();

                RequestProcessor rp = new RequestProcessor();
                rp.Process("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef");

                APNsTableAdapter ata = new APNsTableAdapter();
                DataSet.APNsDataTable adt = ata.GetDataByTitleId(title.Id);
                Expect(adt.Count, Is.EqualTo(1));
                Expect(adt[0].DeviceToken, Is.EqualTo("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));

                SubscriberTableAdapter sta = new SubscriberTableAdapter();
                DataSet.SubscriberDataTable sdt = sta.GetDataByTitleId(title.Id);
                Expect(sdt.Count, Is.EqualTo(1));
                DataSet.SubscriberRow subscriber = sdt[0];
                Expect(subscriber.AuthScheme, Is.EqualTo(AuthScheme.iOS_APNs.ToString()));

                TokenTableAdapter tta = new TokenTableAdapter();
                DataSet.TokenDataTable tdt = tta.GetDataBySubscriberId(subscriber.Id);
                Expect(tdt.Count, Is.EqualTo(1));
            }
        }