(t *testing.T)
| 135 | } |
| 136 | |
| 137 | func TestLoadUserPolicy_Success(t *testing.T) { |
| 138 | // Test that LoadUserPolicy returns the policy when there are no errors |
| 139 | t.Parallel() |
| 140 | |
| 141 | mockUserLookup := &MockUserLookup{User: ValidUser} |
| 142 | policyLoader := NewTestHomePolicyLoader(afero.NewMemMapFs(), mockUserLookup) |
| 143 | mockFs := policyLoader.FileLoader.Fs |
| 144 | // Create policy file at path with valid file |
| 145 | testPolicy := &policy.Policy{ |
| 146 | Users: []policy.User{ |
| 147 | { |
| 148 | IdentityAttribute: "alice@example.com", |
| 149 | Principals: []string{"test"}, |
| 150 | Issuer: "https://example.com", |
| 151 | }, |
| 152 | }, |
| 153 | } |
| 154 | testPolicyFile, err := testPolicy.ToTable() |
| 155 | require.NoError(t, err) |
| 156 | expectedPath := filepath.Join(ValidUser.HomeDir, ".opk", "auth_id") |
| 157 | err = afero.WriteFile(mockFs, expectedPath, testPolicyFile, 0600) |
| 158 | require.NoError(t, err) |
| 159 | |
| 160 | gotPolicy, gotPath, err := policyLoader.LoadHomePolicy(ValidUser.Username, false) |
| 161 | |
| 162 | require.NoError(t, err) |
| 163 | require.Equal(t, testPolicy, gotPolicy) |
| 164 | require.Equal(t, expectedPath, gotPath) |
| 165 | } |
| 166 | |
| 167 | func TestLoadUserPolicy_Success_SkipInvalidEntries(t *testing.T) { |
| 168 | // Test that LoadUserPolicy returns the policy when there are no errors and |
nothing calls this directly
no test coverage detected