MCPcopy
hub / github.com/openpubkey/opkssh / TestLoadUserPolicy_Success

Function TestLoadUserPolicy_Success

policy/policyloader_test.go:137–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func 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
167func TestLoadUserPolicy_Success_SkipInvalidEntries(t *testing.T) {
168 // Test that LoadUserPolicy returns the policy when there are no errors and

Callers

nothing calls this directly

Calls 4

ToTableMethod · 0.95
NewTestHomePolicyLoaderFunction · 0.85
LoadHomePolicyMethod · 0.80
WriteFileMethod · 0.65

Tested by

no test coverage detected