config_syntax_unittest.cc 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <cc/data.h>
  15. #include <config/module_spec.h>
  16. #include <gtest/gtest.h>
  17. using namespace isc::data;
  18. using namespace isc::config;
  19. namespace {
  20. const char* const SPEC_FILE = AUTH_OBJ_DIR "/auth.spec";
  21. class AuthConfigSyntaxTest : public ::testing::Test {
  22. protected:
  23. AuthConfigSyntaxTest() : mspec_(moduleSpecFromFile(SPEC_FILE))
  24. {}
  25. ModuleSpec mspec_;
  26. };
  27. TEST_F(AuthConfigSyntaxTest, inmemoryDefaultFileType) {
  28. // filetype is optional
  29. EXPECT_TRUE(
  30. mspec_.validateConfig(
  31. Element::fromJSON(
  32. "{\"tcp_recv_timeout\": 1000,"
  33. " \"listen_on\": [], \"datasources\": "
  34. " [{\"type\": \"memory\", \"class\": \"IN\", "
  35. " \"zones\": [{\"origin\": \"example.com\","
  36. " \"file\": \""
  37. TEST_DATA_DIR "/example.zone\"}]}]}"), true));
  38. }
  39. TEST_F(AuthConfigSyntaxTest, inmemorySQLite3Backend) {
  40. // Specifying non-default in-memory filetype
  41. EXPECT_TRUE(
  42. mspec_.validateConfig(
  43. Element::fromJSON(
  44. "{\"tcp_recv_timeout\": 1000,"
  45. " \"datasources\": "
  46. " [{\"type\": \"memory\","
  47. " \"zones\": [{\"origin\": \"example.com\","
  48. " \"file\": \""
  49. TEST_DATA_DIR "/example.zone\","
  50. " \"filetype\": \"sqlite3\"}]}]}"), false));
  51. }
  52. TEST_F(AuthConfigSyntaxTest, badInmemoryFileType) {
  53. // filetype must be a string
  54. ASSERT_FALSE(
  55. mspec_.validateConfig(
  56. Element::fromJSON(
  57. "{\"tcp_recv_timeout\": 1000,"
  58. " \"datasources\": "
  59. " [{\"type\": \"memory\","
  60. " \"zones\": [{\"origin\": \"example.com\","
  61. " \"file\": \""
  62. TEST_DATA_DIR "/example.zone\","
  63. " \"filetype\": 42}]}]}"), false));
  64. }
  65. TEST_F(AuthConfigSyntaxTest, badTCPRecvTimeout) {
  66. // tcp_recv_timeout must be int
  67. EXPECT_FALSE(
  68. mspec_.validateConfig(
  69. Element::fromJSON(
  70. "{\"tcp_recv_timeout\": \"foo\","
  71. " \"datasources\": "
  72. " [{\"type\": \"memory\","
  73. " \"zones\": [{\"origin\": \"example.com\","
  74. " \"file\": \""
  75. TEST_DATA_DIR "/example.zone\","
  76. " \"filetype\": \"sqlite3\"}]}]}"), false));
  77. }
  78. }