Example #1
0
TEST_F(TestLink, InsertDelegation)
{
  Link link;
  link.setName(Name("test"));
  link.addDelegation(10,  Name("/test1"));
  link.addDelegation(20,  Name("/test2"));
  link.addDelegation(100, Name("/test3"));

  link.addDelegation(30, Name("/test4"));
  const DelegationSet& delegations = link.getDelegations();
  for (size_t i = 0; i < delegations.size(); ++i) {
    if (i == 0) {
      ASSERT_EQ(10, delegations.get(i).getPreference());
      ASSERT_EQ(Name("/test1"), delegations.get(i).getName());
    }
    if (i == 1) {
      ASSERT_EQ(20, delegations.get(i).getPreference());
      ASSERT_EQ(Name("/test2"), delegations.get(i).getName());
    }
    if (i == 2) {
      ASSERT_EQ(30, delegations.get(i).getPreference());
      ASSERT_EQ(Name("/test4"), delegations.get(i).getName());
    }
    if (i == 3) {
      ASSERT_EQ(100, delegations.get(i).getPreference());
      ASSERT_EQ(Name("/test3"), delegations.get(i).getName());
    }
  }
}
Example #2
0
TEST_F(TestLink, InterestSelectedDelegation)
{
  Link link;
  link.setName(Name("test"));
  link.addDelegation(10,  Name("/test1"));
  link.addDelegation(20,  Name("/test2"));
  link.addDelegation(100, Name("/test3"));

  keyChain_->sign(link, certificateName_);

  Blob linkEncoding = link.wireEncode();

  Interest interestA;
  interestA.setLinkWireEncoding(linkEncoding);
  ASSERT_TRUE(interestA.getSelectedDelegationIndex() < 0);

  interestA.setSelectedDelegationIndex
    (link.getDelegations().find(Name("test2")));
  ASSERT_TRUE(interestA.getSelectedDelegationIndex() >= 0);
  Link* link2 = interestA.getLink();
  ASSERT_EQ
    (Name("test2"),
     link2->getDelegations().get(interestA.getSelectedDelegationIndex()).getName());

  interestA.setSelectedDelegationIndex(-1);
  ASSERT_TRUE(interestA.getSelectedDelegationIndex() < 0);
}
Example #3
0
TEST_F(TestProducer, ProducerWithLink)
{
  Name prefix("/prefix");
  Name suffix("/suffix");
  Name expectedInterest = prefix;
  expectedInterest.append(Encryptor::getNAME_COMPONENT_READ());
  expectedInterest.append(suffix);
  expectedInterest.append(Encryptor::getNAME_COMPONENT_E_KEY());

  MillisecondsSince1970 testTime = fromIsoString("20150101T100001");

  int timeoutCount = 0;

  // Prepare a TestFace to instantly answer calls to expressInterest.
  class TestFace : public Face {
  public:
    TestFace(const Name& expectedInterest, int* timeoutCount)
    : Face("localhost"),
      expectedInterest_(expectedInterest),
      timeoutCount_(timeoutCount)
    {}

    virtual uint64_t
    expressInterest
      (const Interest& interest, const OnData& onData,
       const OnTimeout& onTimeout, const OnNetworkNack& onNetworkNack,
       WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
    {
      if (expectedInterest_ != interest.getName())
        throw runtime_error("TestFace::expressInterest: Not the expectedInterest_");
      if (interest.getLink()->getDelegations().size() != 3)
        throw runtime_error
          ("TestFace::expressInterest: The Interest link does not the expected number of delegates");
      ++(*timeoutCount_);
      onTimeout(ptr_lib::make_shared<Interest>(interest));

      return 0;
    }

  private:
    Name expectedInterest_;
    int* timeoutCount_;
  };

  TestFace face(expectedInterest, &timeoutCount);

  // Verify that if no response is received, the producer appropriately times
  // out. The result vector should not contain elements that have timed out.
  Link link;
  link.addDelegation(10,  Name("/test1"));
  link.addDelegation(20,  Name("/test2"));
  link.addDelegation(100, Name("/test3"));
  keyChain->sign(link);
  ptr_lib::shared_ptr<ProducerDb> testDb(new Sqlite3ProducerDb(databaseFilePath));
  Producer producer(prefix, suffix, &face, keyChain.get(), testDb, 3, link);
  producer.createContentKey
    (testTime,
     bind(&TestProducer::keyTimeoutOnEncryptedKeys, this, _1, &timeoutCount));
}
Example #4
0
TEST_F(TestConsumer, CosumerWithLink)
{
  ptr_lib::shared_ptr<Data> contentData = createEncryptedContent();
  ptr_lib::shared_ptr<Data> cKeyData = createEncryptedCKey();
  ptr_lib::shared_ptr<Data> dKeyData = createEncryptedDKey();

  int contentCount = 0;
  int cKeyCount = 0;
  int dKeyCount = 0;

  // Prepare a TestFace to instantly answer calls to expressInterest.
  class TestFace : public Face {
  public:
    TestFace(ptr_lib::shared_ptr<Data> contentData,
             ptr_lib::shared_ptr<Data> cKeyData,
             ptr_lib::shared_ptr<Data> dKeyData,
             int* contentCount, int* cKeyCount, int* dKeyCount)
    : Face("localhost"),
      contentData_(contentData),
      cKeyData_(cKeyData),
      dKeyData_(dKeyData),
      contentCount_(contentCount),
      cKeyCount_(cKeyCount),
      dKeyCount_(dKeyCount)
    {}

    virtual uint64_t
    expressInterest
      (const Interest& interest, const OnData& onData,
       const OnTimeout& onTimeout, const OnNetworkNack& onNetworkNack,
       WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
    {
      if (interest.getLink()->getDelegations().size() != 3)
        throw runtime_error
          ("TestFace::expressInterest: The Interest link does not the expected number of delegates");

      if (interest.matchesName(contentData_->getName())) {
        *contentCount_ = 1;
        onData(ptr_lib::make_shared<Interest>(interest), contentData_);
      }
      else if (interest.matchesName(cKeyData_->getName())) {
        *cKeyCount_ = 1;
        onData(ptr_lib::make_shared<Interest>(interest), cKeyData_);
      }
      else if (interest.matchesName(dKeyData_->getName())) {
        *dKeyCount_ = 1;
        onData(ptr_lib::make_shared<Interest>(interest), dKeyData_);
      }
      else
        onTimeout(ptr_lib::make_shared<Interest>(interest));

      return 0;
    }

  private:
    ptr_lib::shared_ptr<Data> contentData_;
    ptr_lib::shared_ptr<Data> cKeyData_;
    ptr_lib::shared_ptr<Data> dKeyData_;

    int* contentCount_;
    int* cKeyCount_;
    int* dKeyCount_;
  };

  TestFace face
    (contentData, cKeyData, dKeyData, &contentCount, &cKeyCount, &dKeyCount);

  // Create the consumer.
  Link ckeyLink;
  ckeyLink.addDelegation(10,  Name("/ckey1"));
  ckeyLink.addDelegation(20,  Name("/ckey2"));
  ckeyLink.addDelegation(100, Name("/ckey13"));
  Link dkeyLink;
  dkeyLink.addDelegation(10,  Name("/dkey1"));
  dkeyLink.addDelegation(20,  Name("/dkey2"));
  dkeyLink.addDelegation(100, Name("/dkey13"));
  Link dataLink;
  dataLink.addDelegation(10,  Name("/data1"));
  dataLink.addDelegation(20,  Name("/data2"));
  dataLink.addDelegation(100, Name("/data13"));
  keyChain->sign(ckeyLink);
  keyChain->sign(dkeyLink);
  keyChain->sign(dataLink);

  Consumer consumer
    (&face, keyChain.get(), groupName, uName,
     ptr_lib::make_shared<Sqlite3ConsumerDb>(databaseFilePath),
     ckeyLink, dkeyLink);
  consumer.addDecryptionKey(uKeyName, fixtureUDKeyBlob);

  int finalCount = 0;
  consumer.consume
    (contentName,
     bind(&TestConsumer::onConsumeComplete, this, _1, _2, &finalCount),
     bind(&TestConsumer::onError, this, _1, _2), dataLink);

  ASSERT_EQ(1, contentCount);
  ASSERT_EQ(1, cKeyCount);
  ASSERT_EQ(1, dKeyCount);
  ASSERT_EQ(1, finalCount);
}