Default channel is zapier (xVerae-). Direct api.veraetime.net requires VERAE_ALLOW_DIRECT_VERAE=1. Send x-billing-channel=printit on stamps.
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package auth
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseChannel(t *testing.T) {
|
|
c, err := ParseChannel("zapier")
|
|
if err != nil || c != ChannelZapier {
|
|
t.Fatalf("%v %v", c, err)
|
|
}
|
|
c, err = ParseChannel("")
|
|
if err != nil || c != ChannelZapier {
|
|
t.Fatalf("empty default should be zapier, got %v %v", c, err)
|
|
}
|
|
}
|
|
|
|
func TestPreferredChannelDefaultsToZapier(t *testing.T) {
|
|
t.Setenv("VERAE_PRINT_CHANNEL", "")
|
|
t.Setenv("VERAE_ALLOW_DIRECT_VERAE", "")
|
|
t.Setenv("XVERAE_TOKEN", "")
|
|
if c := PreferredChannel(); c != ChannelZapier {
|
|
t.Fatalf("got %v want zapier (customer signing key path)", c)
|
|
}
|
|
// verae without escape hatch still bills on edge
|
|
t.Setenv("VERAE_PRINT_CHANNEL", "verae")
|
|
if c := PreferredChannel(); c != ChannelZapier {
|
|
t.Fatalf("got %v want zapier when direct verae not allowed", c)
|
|
}
|
|
t.Setenv("VERAE_ALLOW_DIRECT_VERAE", "1")
|
|
if c := PreferredChannel(); c != ChannelVerae {
|
|
t.Fatalf("got %v want verae with escape hatch", c)
|
|
}
|
|
}
|
|
|
|
func TestLoadVeraeJWT(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home) // os.UserHomeDir on Windows
|
|
dir := filepath.Join(home, ".verae")
|
|
if err := os.MkdirAll(dir, 0o700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
path := filepath.Join(dir, "auth.properties")
|
|
body := "# test\naccess_token=tok-abc\nid_token=other\n"
|
|
if err := os.WriteFile(path, []byte(body), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := LoadVeraeJWT()
|
|
if err != nil || got != "tok-abc" {
|
|
t.Fatalf("got %q err %v", got, err)
|
|
}
|
|
}
|