Path: blob/main/crypto/krb5/src/tests/misc/test_chpw_message.c
34907 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* tests/misc/test_getpw.c */2/*3* Copyright (C) 2012 by the Red Hat Inc.4* All rights reserved.5*6* Export of this software from the United States of America may7* require a specific license from the United States Government.8* It is the responsibility of any person or organization contemplating9* export to obtain such a license before exporting.10*11* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and12* distribute this software and its documentation for any purpose and13* without fee is hereby granted, provided that the above copyright14* notice appear in all copies and that both that copyright notice and15* this permission notice appear in supporting documentation, and that16* the name of M.I.T. not be used in advertising or publicity pertaining17* to distribution of the software without specific, written prior18* permission. Furthermore if you modify this software you must label19* your software as modified software and not distribute it in such a20* fashion that it might be confused with the original M.I.T. software.21* M.I.T. makes no representations about the suitability of22* this software for any purpose. It is provided "as is" without express23* or implied warranty.24*/2526#include "autoconf.h"27#include "krb5.h"2829#include <sys/types.h>30#include <assert.h>31#include <locale.h>32#include <stdio.h>33#include <stdlib.h>34#include <string.h>3536static krb5_data result_utf8 = {370, 23, "This is a valid string.",38};3940static krb5_data result_invalid_utf8 = {410, 19, "\0This is not valid.",42};4344static krb5_data result_ad_complex = {450, 30,46"\0\0" /* zero bytes */47"\0\0\0\0" /* min length */48"\0\0\0\0" /* history */49"\0\0\0\1" /* properties, complex */50"\0\0\0\0\0\0\0\0" /* expire */51"\0\0\0\0\0\0\0\0" /* min age */52};5354static krb5_data result_ad_length = {550, 30,56"\0\0" /* zero bytes */57"\0\0\0\x0d" /* min length, 13 characters */58"\0\0\0\0" /* history */59"\0\0\0\0" /* properties */60"\0\0\0\0\0\0\0\0" /* expire */61"\0\0\0\0\0\0\0\0" /* min age */62};6364static krb5_data result_ad_history = {650, 30,66"\0\0" /* zero bytes */67"\0\0\0\0" /* min length */68"\0\0\0\x09" /* history, 9 passwords */69"\0\0\0\0" /* properties */70"\0\0\0\0\0\0\0\0" /* expire */71"\0\0\0\0\0\0\0\0" /* min age */72};7374static krb5_data result_ad_age = {750, 30,76"\0\0" /* zero bytes */77"\0\0\0\0" /* min length */78"\0\0\0\0" /* history, 9 passwords */79"\0\0\0\0" /* properties */80"\0\0\0\0\0\0\0\0" /* expire */81"\0\0\x01\x92\x54\xd3\x80\0" /* min age, 2 days */82};8384static krb5_data result_ad_all = {850, 30,86"\0\0" /* zero bytes */87"\0\0\0\x05" /* min length, 5 characters */88"\0\0\0\x0D" /* history, 13 passwords */89"\0\0\0\x01" /* properties, complex */90"\0\0\0\0\0\0\0\0" /* expire */91"\0\0\0\xc9\x2a\x69\xc0\0" /* min age, 1 day */92};9394static void95check(krb5_error_code code)96{97if (code != 0) {98com_err("t_vfy_increds", code, "");99abort();100}101}102103static void104check_msg(const char *real, const char *expected)105{106if (strstr(real, expected) == NULL) {107fprintf(stderr, "Expected to see: %s\n", expected);108abort();109}110}111112int113main(void)114{115krb5_context context;116char *msg;117118setlocale(LC_ALL, "C");119120check(krb5_init_context(&context));121122/* Valid utf-8 data in the result should be returned as is */123check(krb5_chpw_message(context, &result_utf8, &msg));124printf(" UTF8 valid: %s\n", msg);125check_msg(msg, "This is a valid string.");126free(msg);127128/* Invalid data should have a generic message. */129check(krb5_chpw_message(context, &result_invalid_utf8, &msg));130printf(" UTF8 invalid: %s\n", msg);131check_msg(msg, "contact your administrator");132free(msg);133134/* AD data with complex data requirement */135check(krb5_chpw_message(context, &result_ad_complex, &msg));136printf(" AD complex: %s\n", msg);137check_msg(msg, "The password must include numbers or symbols.");138check_msg(msg, "Don't include any part of your name in the password.");139free(msg);140141/* AD data with min password length */142check(krb5_chpw_message(context, &result_ad_length, &msg));143printf(" AD length: %s\n", msg);144check_msg(msg, "The password must contain at least 13 characters.");145free(msg);146147/* AD data with history requirements */148check(krb5_chpw_message(context, &result_ad_history, &msg));149printf(" AD history: %s\n", msg);150check_msg(msg, "The password must be different from the previous 9 "151"passwords.");152free(msg);153154/* AD data with minimum age */155check(krb5_chpw_message(context, &result_ad_age, &msg));156printf(" AD min age: %s\n", msg);157check_msg(msg, "The password can only be changed every 2 days.");158free(msg);159160/* AD data with all */161check(krb5_chpw_message(context, &result_ad_all, &msg));162printf(" AD all: %s\n", msg);163check_msg(msg, "The password can only be changed once a day.");164check_msg(msg, "The password must be different from the previous 13 "165"passwords.");166check_msg(msg, "The password must contain at least 5 characters.");167check_msg(msg, "The password must include numbers or symbols.");168check_msg(msg, "Don't include any part of your name in the password.");169free(msg);170171krb5_free_context(context);172exit(0);173}174175176