-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstructure_password_policy_test.go
126 lines (120 loc) · 4.13 KB
/
structure_password_policy_test.go
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"reflect"
"testing"
)
var (
testPassPolicyConf *PasswordPolicy
testPassPolicyInterface map[string]interface{}
)
func init() {
TRUE := true
FALSE := false
num1 := 5
num2 := 1
testPassPolicyConf = &PasswordPolicy{
AccountIDMinWordLength: &num1,
AccountNameMinWordLength: &num1,
DefaultPolicy: &FALSE,
Description: "some description",
EnablePasswordExpiration: &FALSE,
FirstExpirationReminder: &num1,
MaxLength: &num2,
MaxRepeatedChars: &num2,
MinAlpha: &num2,
MinCharacterTypes: &num2,
MinLength: &num2,
MinLower: &num2,
MinNumeric: &num2,
MinSpecial: &num2,
MinUpper: &num2,
Name: "some name",
PasswordExpiration: &num1,
RequireStrongAuthOffNetwork: &TRUE,
RequireStrongAuthUntrustedGeographies: &TRUE,
RequireStrongAuthn: &TRUE,
UseAccountAttributes: &TRUE,
UseDictionary: &TRUE,
UseHistory: &num2,
UseIdentityAttributes: &TRUE,
ValidateAgainstAccountID: &TRUE,
ValidateAgainstAccountName: &FALSE,
}
testPassPolicyInterface = map[string]interface{}{
"account_id_min_word_length": num1,
"account_name_min_word_length": num1,
"default_policy": FALSE,
"description": "some description",
"enable_password_expiration": FALSE,
"first_expiration_reminder": num1,
"max_length": num2,
"max_repeated_chars": num2,
"min_alpha": num2,
"min_character_types": num2,
"min_length": num2,
"min_lower": num2,
"min_numeric": num2,
"min_special": num2,
"min_upper": num2,
"name": "some name",
"password_expiration": num1,
"require_strong_auth_off_network": TRUE,
"require_strong_auth_untrusted_geographies": TRUE,
"require_strong_authn": TRUE,
"use_account_attributes": TRUE,
"use_dictionary": TRUE,
"use_history": num2,
"use_identity_attributes": TRUE,
"validate_against_account_id": TRUE,
"validate_against_account_name": FALSE,
}
}
func TestFlattenPasswordPolicy(t *testing.T) {
cases := []struct {
Input *PasswordPolicy
ExpectedOutput map[string]interface{}
}{
{
testPassPolicyConf,
testPassPolicyInterface,
},
}
for _, tc := range cases {
output := schema.TestResourceDataRaw(t, passwordPolicyFields(), tc.ExpectedOutput)
err := flattenPasswordPolicy(output, tc.Input)
if err != nil {
t.Fatalf("[ERROR] on flattener: %#v", err)
}
expectedOutput := map[string]interface{}{}
for k := range tc.ExpectedOutput {
expectedOutput[k] = output.Get(k)
}
if !reflect.DeepEqual(expectedOutput, tc.ExpectedOutput) {
t.Fatalf("Unexpected output from flattener.\nExpected: %#v\nGiven: %#v",
tc.ExpectedOutput, expectedOutput)
}
}
}
func TestExpandPasswordPolicy(t *testing.T) {
cases := []struct {
Input map[string]interface{}
ExpectedOutput *PasswordPolicy
}{
{
testPassPolicyInterface,
testPassPolicyConf,
},
}
for _, tc := range cases {
inputResourceData := schema.TestResourceDataRaw(t, passwordPolicyFields(), tc.Input)
output, err := expandPasswordPolicy(inputResourceData)
if err != nil {
t.Fatalf("[ERROR] on flattener: %#v", err)
}
if !reflect.DeepEqual(output, tc.ExpectedOutput) {
t.Fatalf("Unexpected output from expander.\nExpected: %#v\nGiven: %#v",
tc.ExpectedOutput, output)
}
}
}