LCOV - code coverage report
Current view: top level - tests - old-md5file.c (source / functions) Hit Total Coverage
Test: GNU SASL Lines: 26 33 78.8 %
Date: 2012-05-28 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 18 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* md5file.c --- Test the MD5 file password function.
       2                 :            :  * Copyright (C) 2002-2012 Simon Josefsson
       3                 :            :  *
       4                 :            :  * This file is part of GNU SASL.
       5                 :            :  *
       6                 :            :  * This program is free software: you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation, either version 3 of the License, or
       9                 :            :  * (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18                 :            :  *
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifdef HAVE_CONFIG_H
      22                 :            : #include "config.h"
      23                 :            : #endif
      24                 :            : 
      25                 :            : #include <stdio.h>
      26                 :            : #include <stdarg.h>
      27                 :            : #include <stdlib.h>
      28                 :            : #include <string.h>
      29                 :            : #include <gsasl.h>
      30                 :            : 
      31                 :            : #include "utils.h"
      32                 :            : 
      33                 :            : /* Should match values from cram-md5.pwd. */
      34                 :            : #define BILL "bill"
      35                 :            : #define BILL_PASSWD "hubba-hubba"
      36                 :            : 
      37                 :            : void
      38                 :          1 : doit (void)
      39                 :            : {
      40                 :            :   const char *md5file;
      41                 :            :   char key[BUFSIZ];
      42                 :          1 :   size_t keylen = BUFSIZ - 1;
      43                 :            :   int res;
      44                 :            : 
      45                 :          1 :   md5file = getenv ("MD5FILE");
      46         [ +  - ]:          1 :   if (md5file)
      47                 :            :     {
      48                 :            :       char *p;
      49         [ -  + ]:          1 :       if ((p = strchr (md5file, '=')))
      50                 :          0 :         md5file = p;
      51                 :            :     }
      52                 :            : 
      53         [ -  + ]:          1 :   if (!md5file)
      54                 :          0 :     md5file = "cram-md5.pwd";
      55                 :            : 
      56                 :          1 :   keylen = sizeof (key) - 1;
      57                 :          1 :   res = gsasl_md5pwd_get_password ("non-existing-file", "user", key, &keylen);
      58         [ +  - ]:          1 :   if (res == GSASL_FOPEN_ERROR)
      59                 :          1 :     success ("non-existing-file OK\n");
      60                 :            :   else
      61                 :          0 :     fail ("non-existing-file FAIL (%d): %s\n", res, gsasl_strerror (res));
      62                 :            : 
      63                 :          1 :   keylen = sizeof (key) - 1;
      64                 :          1 :   res = gsasl_md5pwd_get_password (md5file, BILL, key, &keylen);
      65         [ +  - ]:          1 :   if (res == GSASL_OK)
      66                 :          1 :     success ("user-found OK\n");
      67                 :            :   else
      68                 :          0 :     fail ("user-found FAIL (%d): %s\n", res, gsasl_strerror (res));
      69         [ +  - ]:          1 :   if (keylen != strlen (BILL_PASSWD)
      70         [ -  + ]:          1 :       || memcmp (key, BILL_PASSWD, keylen) != 0)
      71                 :          0 :     fail ("user-password FAIL (%lu): %.*s\n",
      72                 :            :           (unsigned long) keylen, (int) keylen, key);
      73                 :            :   else
      74                 :          1 :     success ("user-password OK\n");
      75                 :            : 
      76                 :          1 :   keylen = 5;
      77                 :          1 :   res = gsasl_md5pwd_get_password (md5file, BILL, key, &keylen);
      78         [ +  - ]:          1 :   if (res == GSASL_TOO_SMALL_BUFFER)
      79                 :          1 :     success ("too-small-buffer OK\n");
      80                 :            :   else
      81                 :          0 :     fail ("too-small-buffer FAIL (%d): %s\n", res, gsasl_strerror (res));
      82                 :            : 
      83                 :          1 :   keylen = sizeof (key) - 1;
      84                 :          1 :   res = gsasl_md5pwd_get_password (md5file, "user", key, &keylen);
      85         [ +  - ]:          1 :   if (res == GSASL_AUTHENTICATION_ERROR)
      86                 :          1 :     success ("no-such-user OK\n");
      87                 :            :   else
      88                 :          0 :     fail ("no-such-user FAIL (%d): %s\n", res, gsasl_strerror (res));
      89                 :          1 : }

Generated by: LCOV version 1.9