sid_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package mstypes
  2. import (
  3. "bytes"
  4. "encoding/hex"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "gopkg.in/jcmturner/rpc.v1/ndr"
  8. )
  9. type testSIDStruct struct {
  10. SID RPCSID `ndr:"pointer"`
  11. }
  12. func Test_RPCSIDDecode(t *testing.T) {
  13. var tests = []struct {
  14. Hex string
  15. SID string
  16. }{
  17. {"040000000104000000000005150000005951b81766725d2564633b0b", "S-1-5-21-397955417-626881126-188441444"},
  18. {"05000000010500000000000515000000b9301b2eb7414c6c8c3b351501020000", "S-1-5-21-773533881-1816936887-355810188-513"},
  19. {"050000000105000000000005150000005951b81766725d2564633b0b74542f00", "S-1-5-21-397955417-626881126-188441444-3101812"},
  20. {"050000000105000000000005150000005951b81766725d2564633b0be8383200", "S-1-5-21-397955417-626881126-188441444-3291368"},
  21. {"050000000105000000000005150000005951b81766725d2564633b0b5db43200", "S-1-5-21-397955417-626881126-188441444-3322973"},
  22. {"050000000105000000000005150000005951b81766725d2564633b0b41163500", "S-1-5-21-397955417-626881126-188441444-3479105"},
  23. {"050000000105000000000005150000005951b81766725d2564633b0be8ea3100", "S-1-5-21-397955417-626881126-188441444-3271400"},
  24. {"050000000105000000000005150000005951b81766725d2564633b0bc1193200", "S-1-5-21-397955417-626881126-188441444-3283393"},
  25. {"050000000105000000000005150000005951b81766725d2564633b0b29f13200", "S-1-5-21-397955417-626881126-188441444-3338537"},
  26. {"050000000105000000000005150000005951b81766725d2564633b0b0f5f2e00", "S-1-5-21-397955417-626881126-188441444-3038991"},
  27. {"050000000105000000000005150000005951b81766725d2564633b0b2f5b2e00", "S-1-5-21-397955417-626881126-188441444-3037999"},
  28. {"050000000105000000000005150000005951b81766725d2564633b0bef8f3100", "S-1-5-21-397955417-626881126-188441444-3248111"},
  29. {"050000000105000000000005150000005951b81766725d2564633b0b075f2e00", "S-1-5-21-397955417-626881126-188441444-3038983"},
  30. {"040000000104000000000005150000004c86cebca07160e63fdce887", "S-1-5-21-3167651404-3865080224-2280184895"},
  31. {"050000000105000000000005150000004c86cebca07160e63fdce8875a040000", "S-1-5-21-3167651404-3865080224-2280184895-1114"},
  32. {"050000000105000000000005150000004c86cebca07160e63fdce88757040000", "S-1-5-21-3167651404-3865080224-2280184895-1111"},
  33. }
  34. for i, test := range tests {
  35. a := new(testSIDStruct)
  36. hexStr := TestNDRHeader + "01020304" + test.Hex //The 01000000 is a dumby value for the pointer uint32
  37. b, _ := hex.DecodeString(hexStr)
  38. dec := ndr.NewDecoder(bytes.NewReader(b))
  39. err := dec.Decode(a)
  40. if err != nil {
  41. t.Fatalf("test %d: %v", i+1, err)
  42. }
  43. assert.Equal(t, test.SID, a.SID.String(), "SID not as expected for test %d", i+1)
  44. }
  45. }