Skip to content

Commit

Permalink
fix: dotnettime does not embed the time.Time methods
Browse files Browse the repository at this point in the history
  • Loading branch information
d-strobel committed May 6, 2024
1 parent 1343333 commit 32bcba0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
6 changes: 4 additions & 2 deletions parsing/dotnet_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
// DotnetTime is a custom time type that embeds the time.Time type. It is designed to handle
// the unmarshalling of dotnet JSON datetime strings in the format "\"/Date(timestamp)/\""
// when used as a field in a struct that is being unmarshalled from JSON.
type DotnetTime time.Time
type DotnetTime struct {
time.Time
}

// UnmarshalJSON implements the json.Unmarshaler interface for the DotnetTime type.
// It parses a JSON-encoded dotnet JSON datetime string and converts it into a DotnetTime object.
Expand Down Expand Up @@ -47,7 +49,7 @@ func (t *DotnetTime) UnmarshalJSON(b []byte) error {

// Unmarshal unix time into DotnetTime object
unixTime := time.Unix(seconds, 0).UTC()
*t = DotnetTime(unixTime)
*t = DotnetTime{unixTime}

return nil
}
10 changes: 5 additions & 5 deletions windows/local/accounts/user_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func (suite *LocalAccTestSuite) TestUser1Read() {
Description: "Built-in account for administering the computer/domain",
Enabled: true,
FullName: "",
PasswordChangeableDate: parsing.DotnetTime(time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)),
PasswordChangeableDate: parsing.DotnetTime{Time: time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)},
PasswordExpires: parsing.DotnetTime{},
UserMayChangePassword: true,
PasswordRequired: true,
PasswordLastSet: parsing.DotnetTime(time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)),
PasswordLastSet: parsing.DotnetTime{Time: time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)},
LastLogon: parsing.DotnetTime{},
Name: "Administrator",
SID: accounts.SID{
Expand All @@ -52,11 +52,11 @@ func (suite *LocalAccTestSuite) TestUser2List() {
Description: "Built-in account for administering the computer/domain",
Enabled: true,
FullName: "",
PasswordChangeableDate: parsing.DotnetTime(time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)),
PasswordChangeableDate: parsing.DotnetTime{Time: time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)},
PasswordExpires: parsing.DotnetTime{},
UserMayChangePassword: true,
PasswordRequired: true,
PasswordLastSet: parsing.DotnetTime(time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)),
PasswordLastSet: parsing.DotnetTime{Time: time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)},
LastLogon: parsing.DotnetTime{},
Name: "Administrator",
SID: accounts.SID{
Expand Down Expand Up @@ -102,7 +102,7 @@ func (suite *LocalAccTestSuite) TestUser3Create() {
suite.Equal(accounts.User{Description: "This is a test user"}.Description, g.Description)
suite.Equal(accounts.User{FullName: fmt.Sprintf("Full-Test-User-%d", i)}.FullName, g.FullName)
suite.Equal(accounts.User{PasswordExpires: parsing.DotnetTime{}}.PasswordExpires, g.PasswordExpires)
suite.Equal(accounts.User{AccountExpires: parsing.DotnetTime(time.Date(2025, time.November, 10, 16, 0, 0, 0, time.UTC))}.AccountExpires, g.AccountExpires)
suite.Equal(accounts.User{AccountExpires: parsing.DotnetTime{Time: time.Date(2025, time.November, 10, 16, 0, 0, 0, time.UTC)}}.AccountExpires, g.AccountExpires)
suite.Equal(accounts.User{UserMayChangePassword: false}.UserMayChangePassword, g.UserMayChangePassword)
suite.Equal(accounts.User{Enabled: true}.Enabled, g.Enabled)
}
Expand Down
10 changes: 5 additions & 5 deletions windows/local/accounts/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ var (
Description: "Built-in account for administering the computer/domain",
Enabled: true,
FullName: "",
PasswordChangeableDate: parsing.DotnetTime(time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)),
PasswordChangeableDate: parsing.DotnetTime{Time: time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)},
PasswordExpires: parsing.DotnetTime{},
UserMayChangePassword: true,
PasswordRequired: true,
PasswordLastSet: parsing.DotnetTime(time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)),
PasswordLastSet: parsing.DotnetTime{Time: time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)},
LastLogon: parsing.DotnetTime{},
Name: "Administrator",
SID: SID{
Expand All @@ -41,11 +41,11 @@ var (
Description: "Built-in account for administering the computer/domain",
Enabled: true,
FullName: "",
PasswordChangeableDate: parsing.DotnetTime(time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)),
PasswordChangeableDate: parsing.DotnetTime{Time: time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)},
PasswordExpires: parsing.DotnetTime{},
UserMayChangePassword: true,
PasswordRequired: true,
PasswordLastSet: parsing.DotnetTime(time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)),
PasswordLastSet: parsing.DotnetTime{Time: time.Date(2023, time.November, 30, 21, 25, 5, 0, time.UTC)},
LastLogon: parsing.DotnetTime{},
Name: "Administrator",
SID: SID{
Expand All @@ -70,7 +70,7 @@ var (
},
}
expectedTestUser = User{
AccountExpires: parsing.DotnetTime(time.Date(2025, time.November, 10, 16, 0, 0, 0, time.UTC)),
AccountExpires: parsing.DotnetTime{Time: time.Date(2025, time.November, 10, 16, 0, 0, 0, time.UTC)},
Description: "This is a test user",
Enabled: true,
FullName: "Full-Test-User",
Expand Down

0 comments on commit 32bcba0

Please sign in to comment.