소스 검색

destroy client

Jonathan Turner 7 년 전
부모
커밋
b6307c9200
2개의 변경된 파일32개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      client/client.go
  2. 30 0
      client/client_integration_test.go

+ 2 - 2
client/client.go

@@ -4,7 +4,6 @@ package client
 import (
 import (
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
-	"time"
 
 
 	"gopkg.in/jcmturner/gokrb5.v5/config"
 	"gopkg.in/jcmturner/gokrb5.v5/config"
 	"gopkg.in/jcmturner/gokrb5.v5/credentials"
 	"gopkg.in/jcmturner/gokrb5.v5/credentials"
@@ -217,7 +216,8 @@ func (cl *Client) Login() error {
 
 
 // Destroy stops the auto-renewal of all sessions and removes the sessions and cache entries from the client.
 // Destroy stops the auto-renewal of all sessions and removes the sessions and cache entries from the client.
 func (cl *Client) Destroy() {
 func (cl *Client) Destroy() {
+	creds := credentials.NewCredentials("", "")
 	cl.sessions.destroy()
 	cl.sessions.destroy()
 	cl.Cache.clear()
 	cl.Cache.clear()
-	cl.Credentials.ValidUntil = time.Now().UTC()
+	cl.Credentials = &creds
 }
 }

+ 30 - 0
client/client_integration_test.go

@@ -727,3 +727,33 @@ func TestClient_AutoRenew_Goroutine_Count(t *testing.T) {
 		}
 		}
 	}
 	}
 }
 }
+
+func TestClient_Destroy(t *testing.T) {
+	addr := os.Getenv("TEST_KDC_ADDR")
+	if addr == "" {
+		addr = testdata.TEST_KDC_ADDR
+	}
+	b, _ := hex.DecodeString(testdata.TESTUSER1_KEYTAB)
+	kt, _ := keytab.Parse(b)
+	c, _ := config.NewConfigFromString(testdata.TEST_KRB5CONF)
+	c.Realms[0].KDC = []string{addr + ":" + testdata.TEST_KDC_SHORTTICKETS}
+	cl := NewClientWithKeytab("testuser1", "TEST.GOKRB5", kt)
+	cl.WithConfig(c)
+
+	err := cl.Login()
+	if err != nil {
+		t.Fatalf("error on login: %v\n", err)
+	}
+	spn := "HTTP/host.test.gokrb5"
+	tkt, key, err := cl.GetServiceTicket(spn)
+	if err != nil {
+		t.Fatalf("error getting service ticket: %v\n", err)
+	}
+	n := runtime.NumGoroutine()
+	time.Sleep(time.Second * 120)
+	cl.Destroy()
+	m := runtime.NumGoroutine()
+	t.Logf("DESTROY: %d %d", n, m)
+	assert.True(t, m < n, "auto-renewal goroutine was not stopped when client destroyed")
+	assert.False(t, cl.IsConfigured(), "client is still configured after it was destroyed")
+}