12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package public
- import (
- "github.com/eryajf/chatgpt-dingtalk/config"
- "testing"
- )
- func TestCheckRequestWithCredentials_Pass_WithNilConfig(t *testing.T) {
- Config = &config.Configuration{
- Credentials: nil,
- }
- clientId, pass := CheckRequestWithCredentials("ts", "sg")
- if !pass {
- t.Errorf("pass should be true, but false")
- return
- }
- if len(clientId) > 0 {
- t.Errorf("client id should be empty")
- return
- }
- }
- func TestCheckRequestWithCredentials_Pass_WithEmptyConfig(t *testing.T) {
- Config = &config.Configuration{
- Credentials: []config.Credential{},
- }
- clientId, pass := CheckRequestWithCredentials("ts", "sg")
- if !pass {
- t.Errorf("pass should be true, but false")
- return
- }
- if len(clientId) > 0 {
- t.Errorf("client id should be empty")
- return
- }
- }
- func TestCheckRequestWithCredentials_Pass_WithValidConfig(t *testing.T) {
- Config = &config.Configuration{
- Credentials: []config.Credential{
- config.Credential{
- ClientID: "client-id-for-test",
- ClientSecret: "client-secret-for-test",
- },
- },
- }
- clientId, pass := CheckRequestWithCredentials("1684493546276", "nwBJQmaBLv9+5/sSS/66jcFc1/kGY5wo38L88LOGfRU=")
- if !pass {
- t.Errorf("pass should be true, but false")
- return
- }
- if clientId != "client-id-for-test" {
- t.Errorf("client id should be \"%s\", but \"%s\"", "client-id-for-test", clientId)
- return
- }
- }
- func TestCheckRequestWithCredentials_Failed_WithInvalidConfig(t *testing.T) {
- Config = &config.Configuration{
- Credentials: []config.Credential{
- config.Credential{
- ClientID: "client-id-for-test",
- ClientSecret: "invalid-client-secret-for-test",
- },
- },
- }
- clientId, pass := CheckRequestWithCredentials("1684493546276", "nwBJQmaBLv9+5/sSS/66jcFc1/kGY5wo38L88LOGfRU=")
- if pass {
- t.Errorf("pass should be false, but true")
- return
- }
- if clientId != "" {
- t.Errorf("client id should be empty")
- return
- }
- }
|