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

Function TestLoadUserPolicy_ErrorFile

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

Source from the content-addressed store, hash-verified

115}
116
117func TestLoadUserPolicy_ErrorFile(t *testing.T) {
118 // Test that LoadUserPolicy returns an error when the file is invalid
119 t.Parallel()
120
121 mockUserLookup := &MockUserLookup{User: ValidUser}
122 policyLoader := NewTestHomePolicyLoader(afero.NewMemMapFs(), mockUserLookup)
123 mockFs := policyLoader.FileLoader.Fs
124 // Create policy file at user policy path with invalid data
125 err := afero.WriteFile(mockFs, filepath.Join(ValidUser.HomeDir, ".opk", "auth_id"), []byte("{"), 0600)
126 require.NoError(t, err)
127
128 policy, path, err := policyLoader.LoadHomePolicy(ValidUser.Username, false)
129 require.NoError(t, err)
130 require.False(t, files.ConfigProblems().NoProblems())
131 files.ConfigProblems().Clear()
132
133 require.NotNil(t, policy, "should return policy even if error")
134 require.NotEmpty(t, path, "should return path even if error")
135}
136
137func TestLoadUserPolicy_Success(t *testing.T) {
138 // Test that LoadUserPolicy returns the policy when there are no errors

Callers

nothing calls this directly

Calls 6

ConfigProblemsFunction · 0.92
NewTestHomePolicyLoaderFunction · 0.85
LoadHomePolicyMethod · 0.80
NoProblemsMethod · 0.80
ClearMethod · 0.80
WriteFileMethod · 0.65

Tested by

no test coverage detected