Lutz Justen | 9028140 | 2019-07-05 15:14:37 +0200 | [diff] [blame^] | 1 | // Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "kerberos/krb5_interface_impl.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <gtest/gtest.h> |
| 10 | |
| 11 | namespace kerberos { |
| 12 | |
| 13 | namespace { |
| 14 | |
| 15 | constexpr char kValidConfig[] = ""; |
| 16 | constexpr char kBadKrb5conf[] = "\n\n[libdefaults"; |
| 17 | |
| 18 | } // namespace |
| 19 | |
| 20 | class Krb5InterfaceImplTest : public ::testing::Test { |
| 21 | public: |
| 22 | Krb5InterfaceImplTest() {} |
| 23 | ~Krb5InterfaceImplTest() override = default; |
| 24 | |
| 25 | protected: |
| 26 | Krb5InterfaceImpl krb5_; |
| 27 | |
| 28 | private: |
| 29 | DISALLOW_COPY_AND_ASSIGN(Krb5InterfaceImplTest); |
| 30 | }; |
| 31 | |
| 32 | // Can't test terribly much here since the actual krb5 functionality involves |
| 33 | // network operations. The validation can be tested, though. |
| 34 | |
| 35 | // Tests config validation with a valid config. |
| 36 | TEST_F(Krb5InterfaceImplTest, ValidateConfigSuccess) { |
| 37 | ConfigErrorInfo error_info; |
| 38 | ErrorType error = krb5_.ValidateConfig(kValidConfig, &error_info); |
| 39 | EXPECT_EQ(ERROR_NONE, error); |
| 40 | EXPECT_TRUE(error_info.has_code()); |
| 41 | EXPECT_EQ(CONFIG_ERROR_NONE, error_info.code()); |
| 42 | EXPECT_FALSE(error_info.has_line_index()); |
| 43 | } |
| 44 | |
| 45 | // Tests config validation with a bad config. |
| 46 | TEST_F(Krb5InterfaceImplTest, ValidateConfigFailure) { |
| 47 | ConfigErrorInfo error_info; |
| 48 | ErrorType error = krb5_.ValidateConfig(kBadKrb5conf, &error_info); |
| 49 | EXPECT_EQ(ERROR_BAD_CONFIG, error); |
| 50 | EXPECT_EQ(CONFIG_ERROR_SECTION_SYNTAX, error_info.code()); |
| 51 | EXPECT_TRUE(error_info.has_line_index()); |
| 52 | EXPECT_EQ(2, error_info.line_index()); |
| 53 | } |
| 54 | |
| 55 | // Tests the krb5-part of config validation. |
| 56 | TEST_F(Krb5InterfaceImplTest, ValidateConfigViaKrb5Failure) { |
| 57 | // I didn't see a way to make the krb5-part fail without making the |
| 58 | // ConfigValidator-part fail, so just disable the ConfigValidator-part. |
| 59 | krb5_.DisableConfigValidatorForTesting(); |
| 60 | |
| 61 | ConfigErrorInfo error_info; |
| 62 | ErrorType error = krb5_.ValidateConfig(kBadKrb5conf, &error_info); |
| 63 | EXPECT_EQ(ERROR_BAD_CONFIG, error); |
| 64 | EXPECT_EQ(CONFIG_ERROR_KRB5_FAILED_TO_PARSE, error_info.code()); |
| 65 | EXPECT_FALSE(error_info.has_line_index()); |
| 66 | } |
| 67 | |
| 68 | } // namespace kerberos |