From fe023e2229dedbc646ab7e701ecd1a457dadef16 Mon Sep 17 00:00:00 2001 From: Daniel Molkentin Date: Tue, 16 Sep 2014 23:52:28 +0200 Subject: Allow passing user/pass explicitly or via netrc #2211 --- test/CMakeLists.txt | 1 + test/testnetrcparser.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 test/testnetrcparser.h (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 37ac1e83b..ab0c44003 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,5 +26,6 @@ if( UNIX AND NOT APPLE ) endif(UNIX AND NOT APPLE) owncloud_add_test(CSyncSqlite "") +owncloud_add_test(NetrcParser ../src/owncloudcmd/netrcparser.cpp) diff --git a/test/testnetrcparser.h b/test/testnetrcparser.h new file mode 100644 index 000000000..4ace249dc --- /dev/null +++ b/test/testnetrcparser.h @@ -0,0 +1,76 @@ +/* + * This software is in the public domain, furnished "as is", without technical + * support, and with no warranty, express or implied, as to its usefulness for + * any purpose. + * */ + +#ifndef MIRALL_INOTIFYWATCHER_H +#define MIRALL_INOTIFYWATCHER_H + +#include + +#include "owncloudcmd/netrcparser.h" + +using namespace Mirall; + +namespace { + +const char testfileC[] = "netrctest"; +const char testfileWithDefaultC[] = "netrctestDefault"; +const char testfileEmptyC[] = "netrctestEmpty"; + +} + +class TestNetrcParser : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase() { + QFile netrc(testfileC); + QVERIFY(netrc.open(QIODevice::WriteOnly)); + netrc.write("machine foo login bar password baz\n"); + netrc.write("machine broken login bar2 dontbelonghere password baz2 extratokens dontcare andanother\n"); + netrc.write("machine\nfunnysplit\tlogin bar3 password baz3\n"); + QFile netrcWithDefault(testfileWithDefaultC); + QVERIFY(netrcWithDefault.open(QIODevice::WriteOnly)); + netrcWithDefault.write("machine foo login bar password baz\n"); + netrcWithDefault.write("default login user password pass\n"); + QFile netrcEmpty(testfileEmptyC); + QVERIFY(netrcEmpty.open(QIODevice::WriteOnly)); + } + + void cleanupTestCase() { + QVERIFY(QFile::remove(testfileC)); + QVERIFY(QFile::remove(testfileWithDefaultC)); + QVERIFY(QFile::remove(testfileEmptyC)); + } + + void testValidNetrc() { + NetrcParser parser(testfileC); + QVERIFY(parser.parse()); + QCOMPARE(parser.find("foo"), qMakePair(QString("bar"), QString("baz"))); + QCOMPARE(parser.find("broken"), qMakePair(QString("bar2"), QString("baz2"))); + QCOMPARE(parser.find("funnysplit"), qMakePair(QString("bar3"), QString("baz3"))); + } + + void testEmptyNetrc() { + NetrcParser parser(testfileEmptyC); + QVERIFY(!parser.parse()); + QCOMPARE(parser.find("foo"), qMakePair(QString(), QString())); + } + + void testValidNetrcWithDefault() { + NetrcParser parser(testfileWithDefaultC); + QVERIFY(parser.parse()); + QCOMPARE(parser.find("foo"), qMakePair(QString("bar"), QString("baz"))); + QCOMPARE(parser.find("dontknow"), qMakePair(QString("user"), QString("pass"))); + } + + void testInvalidNetrc() { + NetrcParser parser("/invalid"); + QVERIFY(!parser.parse()); + } +}; + +#endif -- cgit v1.2.3