ea4e3960b8
Keep PEM loading and installation-token provider construction at the CLI leaf, then pass a generic refreshing token provider through the existing HTTP transports. Rebase the feature onto current main and keep the HTTP command unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 646357dd-c89f-4973-9a5c-e6c5fc18818c
39 lines
946 B
Go
39 lines
946 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestLoadAppPrivateKey(t *testing.T) {
|
|
t.Run("file", func(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "app.pem")
|
|
require.NoError(t, os.WriteFile(path, []byte("from-file"), 0o600))
|
|
|
|
key, err := loadAppPrivateKey(path, "from-inline")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []byte("from-file"), key)
|
|
})
|
|
|
|
t.Run("inline", func(t *testing.T) {
|
|
key, err := loadAppPrivateKey("", `first\nsecond`)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []byte("first\nsecond"), key)
|
|
})
|
|
|
|
t.Run("missing", func(t *testing.T) {
|
|
_, err := loadAppPrivateKey("", "")
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "private key")
|
|
})
|
|
}
|
|
|
|
func TestGitHubAppFlagsAreStdioOnly(t *testing.T) {
|
|
assert.NotNil(t, stdioCmd.Flags().Lookup("app-id"))
|
|
assert.Nil(t, httpCmd.Flags().Lookup("app-id"))
|
|
}
|