teleport/lib/services/resetpasswordtoken_test.go
Alexey Kontsevoy 3c670d5d58
Merge Teleport V4.3 UI branch to master (#3583)
* Add monorepo

* Add reset/passwd capability for local users (#3287)

* Add UserTokens to allow password resets

* Pass context down through ChangePasswordWithToken

* Rename UserToken to ResetPasswordToken

* Add auto formatting for proto files

* Add common Marshaller interfaces to reset password token

* Allow enterprise "tctl" reuse OSS user methods (#3344)

* Pass localAuthEnabled flag to UI (#3412)

* Added LocalAuthEnabled prop to WebConfigAuthSetting struct in webconfig.go
* Added LocalAuthEnabled state as part of webCfg in  apiserver.go

* update e-refs

* Fix a regression bug after merge

* Update tctl CLI output msgs (#3442)

* Use local user client when resolving user roles

* Update webapps ref

* Add and retrieve fields from Cluster struct (#3476)

* Set Teleport versions for node, auth, proxy init heartbeat
* Add and retrieve fields NodeCount, PublicURL, AuthVersion from Clusters
* Remove debug logging to avoid log pollution when getting public_addr of proxy
* Create helper func GuessProxyHost to get the public_addr of a proxy host
* Refactor newResetPasswordToken to use GuessProxyHost and remove publicUrl func

* Remove webapps submodule

* Add webassets submodule

* Replace webapps sub-module reference with webassets

* Update webassets path in Makefile

* Update webassets

1b11b26 Simplify and clean up Makefile (#62) https://github.com/gravitational/webapps/commit/1b11b26

* Retrieve cluster details for user context (#3515)

* Let GuessProxyHost also return proxy's version
* Unit test GuessProxyHostAndVersion & GetClusterDetails

* Update webassets

4dfef4e Fix build pipeline (#66) https://github.com/gravitational/webapps/commit/4dfef4e

* Update e-ref

* Update webassets

0647568 Fix OSS redirects https://github.com/gravitational/webapps/commit/0647568

* update e-ref

* Update webassets

e0f4189 Address security audit warnings Updates  "minimist" package which is used by 7y old "optimist". https://github.com/gravitational/webapps/commit/e0f4189

* Add new attr to Session struct (#3574)

* Add fields ServerHostname and ServerAddr
* Set these fields on newSession

* Ensure webassets submodule during build

* Update e-ref

* Ensure webassets before running unit-tests

* Update E-ref

Co-authored-by: Lisa Kim <lisa@gravitational.com>
Co-authored-by: Pierre Beaucamp <pierre@gravitational.com>
Co-authored-by: Jenkins <jenkins@gravitational.io>
2020-04-15 15:35:26 -04:00

92 lines
2.3 KiB
Go

/*
Copyright 2020 Gravitational, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package services
import (
"fmt"
"time"
"github.com/gravitational/teleport/lib/fixtures"
"github.com/gravitational/teleport/lib/utils"
"gopkg.in/check.v1"
)
type ResetPasswordTokenSuite struct{}
var _ = check.Suite(&ResetPasswordTokenSuite{})
var _ = fmt.Printf
func (s *ResetPasswordTokenSuite) SetUpSuite(c *check.C) {
utils.InitLoggerForTests()
}
func (s *ResetPasswordTokenSuite) TestUnmarshal(c *check.C) {
created, err := time.Parse(time.RFC3339, "2020-01-14T18:52:39.523076855Z")
c.Assert(err, check.IsNil)
type testCase struct {
description string
input string
expected ResetPasswordToken
}
testCases := []testCase{
{
description: "simple case",
input: `
{
"kind": "user_token",
"version": "v3",
"metadata": {
"name": "tokenId"
},
"spec": {
"user": "example@example.com",
"created": "2020-01-14T18:52:39.523076855Z",
"url": "https://localhost"
}
}
`,
expected: &ResetPasswordTokenV3{
Kind: KindResetPasswordToken,
Version: V3,
Metadata: Metadata{
Name: "tokenId",
},
Spec: ResetPasswordTokenSpecV3{
Created: created,
User: "example@example.com",
URL: "https://localhost",
},
},
},
}
marshaler := GetResetPasswordTokenMarshaler()
for _, tc := range testCases {
comment := check.Commentf("test case %q", tc.description)
out, err := marshaler.Unmarshal([]byte(tc.input))
c.Assert(err, check.IsNil, comment)
fixtures.DeepCompare(c, tc.expected, out)
data, err := marshaler.Marshal(out)
c.Assert(err, check.IsNil, comment)
out2, err := marshaler.Unmarshal(data)
c.Assert(err, check.IsNil, comment)
fixtures.DeepCompare(c, tc.expected, out2)
}
}