Przeglądaj źródła

investigating potential issues

Jonathan Turner 5 lat temu
rodzic
commit
62878abe50
3 zmienionych plików z 64 dodań i 0 usunięć
  1. 7 0
      v8/keytab/keytab_test.go
  2. 1 0
      v8/spnego/http.go
  3. 56 0
      v8/spnego/negotiationToken_test.go

+ 7 - 0
v8/keytab/keytab_test.go

@@ -99,6 +99,13 @@ func TestLoad(t *testing.T) {
 	}
 }
 
+func TestLoadIncorrectPath(t *testing.T) {
+	_, err := Load(os.TempDir() + "/doesnotexist.keytab")
+	if err == nil {
+		t.Error("keytab loading did not error when path was invalid")
+	}
+}
+
 // This test provides inputs to readBytes that previously
 // caused a panic.
 func TestReadBytes(t *testing.T) {

+ 1 - 0
v8/spnego/http.go

@@ -72,6 +72,7 @@ func NewClient(krb5Cl *client.Client, httpCl *http.Client, spn string) *Client {
 		}
 		return redirectErr{reqTarget: req}
 	}
+
 	return &Client{
 		Client:     httpCl,
 		krb5Client: krb5Cl,

+ 56 - 0
v8/spnego/negotiationToken_test.go

@@ -5,6 +5,7 @@ import (
 	"testing"
 
 	"github.com/jcmturner/gofork/encoding/asn1"
+	"github.com/jcmturner/gokrb5/v8/gssapi"
 	"github.com/stretchr/testify/assert"
 )
 
@@ -88,3 +89,58 @@ func TestMarshal_negTokenResp(t *testing.T) {
 	}
 	assert.Equal(t, b, mb, "Marshalled bytes not as expected for NegTokenResp")
 }
+
+func TestUnmarshal_negTokenInitWithReqFlags(t *testing.T) {
+	//t.Parallel()
+	//b, err := hex.DecodeString(testNegTokenInit)
+	//if err != nil {
+	//	t.Fatalf("Error converting hex string test data to bytes: %v", err)
+	//}
+	//isInit, nt, err := UnmarshalNegToken(b)
+	//if err != nil {
+	//	t.Fatalf("Error unmarshalling negotiation token: %v", err)
+	//}
+	//assert.IsType(t, NegTokenInit{}, nt, "Not the expected type NegTokenInit")
+	//assert.True(t, isInit, "Boolean indicating type is negTokenInit is not true")
+	//nInit := nt.(NegTokenInit)
+	//
+	//// Now add some ReqFlags
+	//nInit.ReqFlags = gssapi.NewContextFlags()
+	//nInit.ReqFlags.Bytes = []byte{0xF6}
+	//mb, err := nInit.Marshal()
+	//if err != nil {
+	//	t.Fatalf("could not marshal with ReqFlags: %v", err)
+	//}
+	//t.Logf("MB: %s\n", hex.EncodeToString(mb))
+	//
+	//isInit, nt, err = UnmarshalNegToken(mb)
+	//if err != nil {
+	//	t.Fatalf("Error unmarshalling negotiation token: %v", err)
+	//}
+	//assert.IsType(t, NegTokenInit{}, nt, "Not the expected type NegTokenInit")
+	//assert.True(t, isInit, "Boolean indicating type is negTokenInit is not true")
+	//nInit2 := nt.(NegTokenInit)
+	//t.Logf("nt2: %+v\n", nInit2)
+	//assert.Equal(t, nInit.MechTokenBytes, nInit2.MechTokenBytes)
+
+	m := NegTokenInit{
+		MechTypes: []asn1.ObjectIdentifier{
+			asn1.ObjectIdentifier{1, 2, 840, 113554, 1, 2, 2},
+		},
+		// the presence of ReqFlags field messes up the asn1 parser. comment
+		ReqFlags:       gssapi.ContextFlags{BitLength: 7, Bytes: []byte{0xF6}},
+		MechTokenBytes: []byte{'\x01', '\x02', '\x03'},
+	}
+
+	mb, err := m.Marshal()
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	var m2 NegTokenInit
+	err = m2.Unmarshal(mb)
+	if err != nil {
+		t.Fatal(err)
+	}
+	t.Logf("%+v/n", m2)
+}