security: StreamSource throws upon istream::fail()
refs #3741
Change-Id: I3742655ecfd93d47198c83b61664f8cea345d33e
diff --git a/src/security/transform/stream-source.cpp b/src/security/transform/stream-source.cpp
index 5248646..539506e 100644
--- a/src/security/transform/stream-source.cpp
+++ b/src/security/transform/stream-source.cpp
@@ -53,7 +53,7 @@
dataOffset += nBytesWritten;
dataLen -= nBytesWritten;
}
- else if (m_is.bad()) {
+ else if (!m_is) {
BOOST_THROW_EXCEPTION(Error(getIndex(), "Input stream in bad state"));
}
else if (m_is.good()) {
diff --git a/tests/unit-tests/security/transform/stream-source.t.cpp b/tests/unit-tests/security/transform/stream-source.t.cpp
index a2f7be3..edce9f1 100644
--- a/tests/unit-tests/security/transform/stream-source.t.cpp
+++ b/tests/unit-tests/security/transform/stream-source.t.cpp
@@ -23,6 +23,8 @@
#include "security/transform/stream-sink.hpp"
#include "boost-test.hpp"
+#include <boost/mpl/integral_c.hpp>
+#include <boost/mpl/vector.hpp>
namespace ndn {
namespace security {
@@ -65,6 +67,28 @@
BOOST_CHECK_EQUAL(input, output);
}
+BOOST_AUTO_TEST_CASE(EmptyStream)
+{
+ std::stringstream is;
+ std::stringstream os;
+ streamSource(is) >> streamSink(os);
+
+ BOOST_CHECK_EQUAL(os.str(), "");
+}
+
+typedef boost::mpl::vector<
+ boost::mpl::integral_c<std::ios_base::iostate, std::ios_base::badbit>,
+ boost::mpl::integral_c<std::ios_base::iostate, std::ios_base::failbit>
+> BadBits;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(BadStream, BadBit, BadBits)
+{
+ std::stringstream is;
+ is.setstate(BadBit::value);
+ std::stringstream os;
+ BOOST_CHECK_THROW(streamSource(is) >> streamSink(os), transform::Error);
+}
+
BOOST_AUTO_TEST_SUITE_END() // TestStreamSource
BOOST_AUTO_TEST_SUITE_END() // Transform
BOOST_AUTO_TEST_SUITE_END() // Security
diff --git a/tests/unit-tests/util/io.t.cpp b/tests/unit-tests/util/io.t.cpp
index 9d6ec03..f8ea2ae 100644
--- a/tests/unit-tests/util/io.t.cpp
+++ b/tests/unit-tests/util/io.t.cpp
@@ -191,7 +191,6 @@
BOOST_AUTO_TEST_CASE(LoadFileNotReadable)
{
- this->mkdir();
shared_ptr<DecodableType> decoded;
BOOST_CHECK_NO_THROW(decoded = io::load<DecodableType>(filename, io::NO_ENCODING));
BOOST_CHECK(decoded == nullptr);