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

Function TestLoginCustomKeyPath

test/integration/login_test.go:126–221  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func TestLoginCustomKeyPath(t *testing.T) {
127 tests := []struct {
128 name string
129 keyType commands.KeyType
130 }{
131 {
132 name: "ECDSA Key",
133 keyType: commands.ECDSA,
134 },
135 {
136 name: "ED25519 Key",
137 keyType: commands.ED25519,
138 },
139 }
140
141 for _, tt := range tests {
142 t.Run(tt.name, func(t *testing.T) {
143 // Check that user can login and that valid openpubkey keys are written to
144 // the correct places on disk
145
146 // Setup fake OIDC server on localhost
147 t.Log("------- setup OIDC server on localhost ------")
148 opServer, err := NewFakeOpServer()
149 require.NoError(t, err, "failed to create fake OIDC server")
150 defer opServer.Close()
151 t.Logf("OP server running at %s", opServer.URL)
152
153 // Call login
154 t.Log("------- call login cmd ------")
155 errCh := make(chan error)
156 opkProvider, loginURL, err := opServer.OpkProvider()
157 require.NoError(t, err, "failed to create OPK provider")
158
159 homePath, err := os.UserHomeDir()
160
161 require.NoError(t, err)
162
163 sshPath := filepath.Join(homePath, ".ssh")
164
165 // Make ~/.ssh if folder does not exist
166 err = os.MkdirAll(sshPath, os.ModePerm)
167 require.NoError(t, err)
168
169 seckeyPath := filepath.Join(sshPath, "opkssh-key")
170 defer removeKey(seckeyPath)
171
172 go func() {
173 loginCmd := commands.LoginCmd{Fs: afero.NewOsFs(), KeyTypeArg: tt.keyType}
174 err := loginCmd.Login(TestCtx, opkProvider, false, seckeyPath)
175 errCh <- err
176 }()
177
178 // Wait for auth callback server on localhost to come up. It should come up
179 // when login command is called
180 timeoutErr := WaitForServer(TestCtx, fmt.Sprintf("%s://%s", loginURL.Scheme, loginURL.Host), LoginCallbackServerTimeout)
181 require.NoError(t, timeoutErr, "login callback server took too long to startup")
182
183 // Do OIDC login

Callers

nothing calls this directly

Calls 11

OpkProviderMethod · 0.95
LoginMethod · 0.95
NewFakeOpServerFunction · 0.85
removeKeyFunction · 0.85
WaitForServerFunction · 0.85
DoOidcInteractiveLoginFunction · 0.85
GetOPKSshKeyFunction · 0.85
MkdirAllMethod · 0.65
ReadFileMethod · 0.65
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected