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));
            }
        }
Ejemplo n.º 2
0
 public override void Error(ErrorStatus errorStatus)
 {
     switch (errorStatus)
     {
         case ErrorStatus.InvalidToken:
             {
                 APNsTableAdapter ta = new APNsTableAdapter();
                 ta.UpdateInvalidDeviceToken(apnsId);
                 break;
             }
         default:
             logger.Error("APNs returned error:" + errorStatus.ToString() + " APNs id:" + apnsId);
             break;
     }
 }
Ejemplo n.º 3
0
        private bool AuthenticateRequestImpl(HttpContext context)
        {
            string tokenBody = context.Request.Headers[SiteConstant.AuthTokenRequestResposeHeaderName];
            if (tokenBody == null)
            {
                logger.Info("�F�؃g�[�N���̂Ȃ����N�G�X�g������܂����BRequestInfo: " + WebUtil.RequestInfo(context));
                return false;
            }

            logger.Info("token:" + tokenBody + " RequestInfo:" + WebUtil.RequestInfo(context));
            TokenVerifier v = new TokenVerifier(tokenBody, now);
            if (!v.IsValid)
            {
                logger.Info("token invalid. RequestInfo: " + WebUtil.RequestInfo(context));
                return false;
            }
            if (!v.IsAuthScheme(AuthScheme.iOS_APNs))
            {
                logger.Info("scheme is not APNs. RequestInfo: " + WebUtil.RequestInfo(context));
                // return false;
            }
            if (v.IsLockedOut)
            {
                logger.Info("token is locked out. RequestInfo: " + WebUtil.RequestInfo(context));
                // return false;
            }
            if (!v.IsLiving)
            {
                logger.Info("token is not living. RequestInfo: " + WebUtil.RequestInfo(context));
                // return false;
            }
            if (v.IsOutdated)
            {
                logger.Info("token is Outdated. RequestInfo: " + WebUtil.RequestInfo(context));
                context.Response.Headers[SiteConstant.AuthStatusRequestResposeHeaderName] = "Outdated";
            }

            APNsTableAdapter ata = new APNsTableAdapter();
            DataSet.APNsDataTable adt = ata.GetDataBySubscriberId(v.Subscriber.Id);
            if (adt[0].UnreadRelease > 0)
            {
                adt[0].UnreadRelease = 0;
                ata.Update(adt);
            }

            context.User = new GenericPrincipal(new GenericIdentity("user"), null);
            return true;
        }
        public void Test_Process_ExistSubscriber()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                DataSet.TitleRow title = PrepareBasic();
                DataSet.SubscriberRow subscriber = PrepareExist(title);

                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"));

                TokenTableAdapter tta = new TokenTableAdapter();
                DataSet.TokenDataTable tdt = tta.GetDataBySubscriberId(subscriber.Id);
                Expect(tdt.Count, Is.EqualTo(2));
            }
        }
Ejemplo n.º 5
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));
            }
        }
Ejemplo n.º 6
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));
            }
        }
        public void Test_Process_ExistSubscriber_ApnsFailed()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                DataSet.TitleRow title = PrepareBasic();
                DataSet.SubscriberRow subscriber = PrepareExist(title);

                APNsTableAdapter ata = new APNsTableAdapter();
                DataSet.APNsDataTable adt = ata.GetDataByTitleId(title.Id);
                adt[0].Failed = true;
                ata.Update(adt);

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

                adt = ata.GetDataByTitleId(title.Id);
                Expect(adt[0].Failed, Is.EqualTo(false));
            }
        }
        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));
            }
        }