aboutsummaryrefslogtreecommitdiff
path: root/databases/passwords/sql/test.py
blob: bfacb20a24a6b7ec2d99abfe6d54eba5089b2998 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Checks SQL Server user data for compliance with Windows policies.
"""

# Import packages
import pandas as pd

# Load the data into a pandas DataFrame
df_input = pd.read_csv('./data.csv')

# Function to apply rules and generate report
def apply_rules_and_report(df):
    """
    Apply defined rules against the input data.

            Parameters:
                df (pandas.DataFrame): SQL login data

            Returns:
                report (list): List of dictionaries containing test results
    """
    report = []
    for _, row in df.iterrows():
        result = {
            'Name': row['name'],
            'Type Check': '',
            'Policy Check': '',
            'Expiration Check': '',
            'Reason': ''
        }

        # Check the type_desc
        if row['type_desc'] == 'SQL_LOGIN':
            result['Type Check'] = 'SQL_LOGIN'
        elif row['type_desc'] == 'WINDOWS_LOGIN':
            result['Type Check'] = 'N/A'
            result['Reason'] = 'Refer to Windows password policy.'
        else:
            result['Type Check'] = 'Manual Review'
            result['Reason'] = 'Reviewer to manually review.'

        # Check if password policy is enforced
        if row['is_policy_checked'] == 1:
            result['Policy Check'] = 'PASS'
            result['Reason'] += '''Password policy is enforced. Reviewer to
            check the assigned policy.'''
        else:
            result['Policy Check'] = 'FAIL'
            result['Reason'] += 'Password policy is not enforced.'

        # Check if password expiration is enforced
        if row['is_expiration_checked'] == 1:
            result['Expiration Check'] = 'PASS'
            result['Reason'] += '''Password expiration is enforced. Reviewer to
            check the expiration policy.'''
        else:
            result['Expiration Check'] = 'FAIL'
            result['Reason'] += 'Password expiration is not enforced.'

        report.append(result)

    return report

# Main function to run the script
def main():
    """
    Apply defined rules against the input data and print the results.
    """
    # Apply rules and generate report
    report = apply_rules_and_report(df_input)
    report_df = pd.DataFrame(report)

    # Print the report
    print(report_df)

if __name__ == "__main__":
    main()