LCOV - code coverage report
Current view: top level - lib/util/tests - genrand.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 25 27 92.6 %
Date: 2024-04-21 15:09:00 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    local testing of random data routines.
       5             : 
       6             :    Copyright (C) Jelmer Vernooij <jelmer@samba.org>
       7             :    
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             :    
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             :    
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "torture/torture.h"
      24             : #include "torture/local/proto.h"
      25             : 
      26           1 : static bool test_check_password_quality(struct torture_context *tctx)
      27             : {
      28           1 :         torture_assert(tctx, !check_password_quality(""), "empty password");
      29           1 :         torture_assert(tctx, !check_password_quality("a"), "one char password");
      30           1 :         torture_assert(tctx, !check_password_quality("aaaaaaaaaaaa"), "same char password");
      31           1 :         torture_assert(tctx, !check_password_quality("BLA"), "multiple upcases password");
      32           1 :         torture_assert(tctx, !check_password_quality("123"), "digits only");
      33           1 :         torture_assert(tctx, !check_password_quality("matthiéu"), "not enough high symbols");
      34           1 :         torture_assert(tctx, !check_password_quality("abcdééàçè"), "only lower case");
      35           1 :         torture_assert(tctx, !check_password_quality("abcdééàçè+"), "only lower and symbols");
      36           1 :         torture_assert(tctx, check_password_quality("abcdééàçè+ढ"), "valid");
      37           1 :         torture_assert(tctx, check_password_quality("ç+ढ"), "valid");
      38           1 :         torture_assert(tctx, check_password_quality("A2e"), "valid");
      39           1 :         torture_assert(tctx, check_password_quality("BA2eLi443"), "valid");
      40           0 :         return true;
      41             : }
      42             : 
      43           1 : static bool test_generate_random_str(struct torture_context *tctx)
      44             : {
      45           1 :         TALLOC_CTX *mem_ctx = talloc_init(__FUNCTION__);
      46           1 :         char *r = generate_random_str(mem_ctx, 10);
      47           1 :         torture_assert_int_equal(tctx, strlen(r), 10, "right length generated");
      48           1 :         r = generate_random_str(mem_ctx, 5);
      49           1 :         torture_assert_int_equal(tctx, strlen(r), 5, "right length generated");
      50             : 
      51           1 :         TALLOC_FREE(mem_ctx);
      52           0 :         return true;
      53             : }
      54             : 
      55        2354 : struct torture_suite *torture_local_genrand(TALLOC_CTX *mem_ctx)
      56             : {
      57        2354 :         struct torture_suite *suite = torture_suite_create(mem_ctx, "genrand");
      58        2354 :         torture_suite_add_simple_test(suite, "check_password_quality", test_check_password_quality);
      59        2354 :         torture_suite_add_simple_test(suite, "generate_random_str", test_generate_random_str);
      60        2354 :         return suite;
      61             : }

Generated by: LCOV version 1.14