From b13382ec9d02e6379d78d1298dbe441b11c1d58c Mon Sep 17 00:00:00 2001 From: Artem Gavrilov Date: Tue, 28 Jul 2020 18:41:36 +0200 Subject: [PATCH 1/3] Revert "SAAS-174 Remove password reset tests" This reverts commit e4efc6c8e51d3dda3beee5056d54232a7c6e0326. --- server/platform_auth_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/server/platform_auth_test.go b/server/platform_auth_test.go index f599fe9d..46e4e0c2 100644 --- a/server/platform_auth_test.go +++ b/server/platform_auth_test.go @@ -142,4 +142,35 @@ func TestPlatform(t *testing.T) { pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid field Password: value '' must not be an empty string") }) }) + + t.Run("password reset", func(t *testing.T) { + email := gofakeit.Email() + password := gofakeit.Password(true, true, true, false, false, 14) + + _, err := client.PlatformSignUp(&server.PlatformSignUpParams{ + Body: server.PlatformSignUpBody{ + Email: email, + Password: password, + }, + Context: pmmapitests.Context, + }) + require.NoError(t, err) + + _, err = client.PlatformResetPassword(&server.PlatformResetPasswordParams{ + Body: server.PlatformResetPasswordBody{ + Email: email, + }, + Context: pmmapitests.Context, + }) + require.NoError(t, err) + + _, err = client.PlatformSignIn(&server.PlatformSignInParams{ + Body: server.PlatformSignInBody{ + Email: email, + Password: password, + }, + Context: pmmapitests.Context, + }) + pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "Incorrect username or password.") + }) } From 141acd6270c0da424221817e7b74e99ff069a3fa Mon Sep 17 00:00:00 2001 From: Artem Gavrilov Date: Tue, 28 Jul 2020 18:41:57 +0200 Subject: [PATCH 2/3] Revert "SAAS-175 Remove password reset permission test" This reverts commit 6a22021ffe7fc1e708803aa70c075b9378fd8919. --- server/auth_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/auth_test.go b/server/auth_test.go index 4e77fd0c..5a566cbb 100644 --- a/server/auth_test.go +++ b/server/auth_test.go @@ -275,6 +275,12 @@ func TestPermissions(t *testing.T) { {userType: "editor", login: editor, statusCode: 401}, {userType: "admin", login: admin, statusCode: 400}, // We send bad request, but have access to endpoint }}, + {name: "platform-reset-password", url: "/v1/Platform/ResetPassword", method: "POST", userCase: []userCase{ + {userType: "default", login: none, statusCode: 401}, + {userType: "viewer", login: viewer, statusCode: 401}, + {userType: "editor", login: editor, statusCode: 401}, + {userType: "admin", login: admin, statusCode: 400}, // We send bad request, but have access to endpoint + }}, } for _, test := range tests { From 4ee4d8e8d336a3780e548d79fbc2945617b3a867 Mon Sep 17 00:00:00 2001 From: Artem Gavrilov Date: Tue, 28 Jul 2020 19:31:10 +0200 Subject: [PATCH 3/3] SAAS-174 Update pmm dependency --- Gopkg.lock | 6 +- Gopkg.toml | 2 +- .../platform_reset_password_parameters.go | 131 ++++++++++ .../platform_reset_password_responses.go | 223 ++++++++++++++++++ .../json/client/server/server_client.go | 35 +++ 5 files changed, 393 insertions(+), 4 deletions(-) create mode 100644 vendor/github.com/percona/pmm/api/serverpb/json/client/server/platform_reset_password_parameters.go create mode 100644 vendor/github.com/percona/pmm/api/serverpb/json/client/server/platform_reset_password_responses.go diff --git a/Gopkg.lock b/Gopkg.lock index 958d67aa..9f3a652a 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -217,8 +217,8 @@ version = "1.0.1" [[projects]] - branch = "PMM-2.0" - digest = "1:3fb7d13ce8ea1ea169eaef1436e820150a4e6ddfe1c817bb47c93c4bbd2ecc1e" + branch = "SAAS-174-password-reset" + digest = "1:a613726824eb8b8a4a70174846506cb459c10207b42811f05bffa1f99703fb9b" name = "github.com/percona/pmm" packages = [ "api/alertmanager/amclient", @@ -249,7 +249,7 @@ "utils/tlsconfig", ] pruneopts = "NUT" - revision = "c538a89c38d8ab0fcaebd2c1ff02c581106f7bca" + revision = "608eee5a2eef3c33a7051f08535d8c8d6b92cc30" [[projects]] digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" diff --git a/Gopkg.toml b/Gopkg.toml index 9706ce95..9365b50e 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -10,4 +10,4 @@ required = [ [[constraint]] name = "github.com/percona/pmm" - branch = "PMM-2.0" + branch = "SAAS-174-password-reset" diff --git a/vendor/github.com/percona/pmm/api/serverpb/json/client/server/platform_reset_password_parameters.go b/vendor/github.com/percona/pmm/api/serverpb/json/client/server/platform_reset_password_parameters.go new file mode 100644 index 00000000..79515a91 --- /dev/null +++ b/vendor/github.com/percona/pmm/api/serverpb/json/client/server/platform_reset_password_parameters.go @@ -0,0 +1,131 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package server + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" +) + +// NewPlatformResetPasswordParams creates a new PlatformResetPasswordParams object +// with the default values initialized. +func NewPlatformResetPasswordParams() *PlatformResetPasswordParams { + var () + return &PlatformResetPasswordParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewPlatformResetPasswordParamsWithTimeout creates a new PlatformResetPasswordParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewPlatformResetPasswordParamsWithTimeout(timeout time.Duration) *PlatformResetPasswordParams { + var () + return &PlatformResetPasswordParams{ + + timeout: timeout, + } +} + +// NewPlatformResetPasswordParamsWithContext creates a new PlatformResetPasswordParams object +// with the default values initialized, and the ability to set a context for a request +func NewPlatformResetPasswordParamsWithContext(ctx context.Context) *PlatformResetPasswordParams { + var () + return &PlatformResetPasswordParams{ + + Context: ctx, + } +} + +// NewPlatformResetPasswordParamsWithHTTPClient creates a new PlatformResetPasswordParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewPlatformResetPasswordParamsWithHTTPClient(client *http.Client) *PlatformResetPasswordParams { + var () + return &PlatformResetPasswordParams{ + HTTPClient: client, + } +} + +/*PlatformResetPasswordParams contains all the parameters to send to the API endpoint +for the platform reset password operation typically these are written to a http.Request +*/ +type PlatformResetPasswordParams struct { + + /*Body*/ + Body PlatformResetPasswordBody + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the platform reset password params +func (o *PlatformResetPasswordParams) WithTimeout(timeout time.Duration) *PlatformResetPasswordParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the platform reset password params +func (o *PlatformResetPasswordParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the platform reset password params +func (o *PlatformResetPasswordParams) WithContext(ctx context.Context) *PlatformResetPasswordParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the platform reset password params +func (o *PlatformResetPasswordParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the platform reset password params +func (o *PlatformResetPasswordParams) WithHTTPClient(client *http.Client) *PlatformResetPasswordParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the platform reset password params +func (o *PlatformResetPasswordParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithBody adds the body to the platform reset password params +func (o *PlatformResetPasswordParams) WithBody(body PlatformResetPasswordBody) *PlatformResetPasswordParams { + o.SetBody(body) + return o +} + +// SetBody adds the body to the platform reset password params +func (o *PlatformResetPasswordParams) SetBody(body PlatformResetPasswordBody) { + o.Body = body +} + +// WriteToRequest writes these params to a swagger request +func (o *PlatformResetPasswordParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if err := r.SetBodyParam(o.Body); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/vendor/github.com/percona/pmm/api/serverpb/json/client/server/platform_reset_password_responses.go b/vendor/github.com/percona/pmm/api/serverpb/json/client/server/platform_reset_password_responses.go new file mode 100644 index 00000000..424c0162 --- /dev/null +++ b/vendor/github.com/percona/pmm/api/serverpb/json/client/server/platform_reset_password_responses.go @@ -0,0 +1,223 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package server + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// PlatformResetPasswordReader is a Reader for the PlatformResetPassword structure. +type PlatformResetPasswordReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *PlatformResetPasswordReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewPlatformResetPasswordOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewPlatformResetPasswordDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewPlatformResetPasswordOK creates a PlatformResetPasswordOK with default headers values +func NewPlatformResetPasswordOK() *PlatformResetPasswordOK { + return &PlatformResetPasswordOK{} +} + +/*PlatformResetPasswordOK handles this case with default header values. + +A successful response. +*/ +type PlatformResetPasswordOK struct { + Payload interface{} +} + +func (o *PlatformResetPasswordOK) Error() string { + return fmt.Sprintf("[POST /v1/Platform/ResetPassword][%d] platformResetPasswordOk %+v", 200, o.Payload) +} + +func (o *PlatformResetPasswordOK) GetPayload() interface{} { + return o.Payload +} + +func (o *PlatformResetPasswordOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewPlatformResetPasswordDefault creates a PlatformResetPasswordDefault with default headers values +func NewPlatformResetPasswordDefault(code int) *PlatformResetPasswordDefault { + return &PlatformResetPasswordDefault{ + _statusCode: code, + } +} + +/*PlatformResetPasswordDefault handles this case with default header values. + +An unexpected error response +*/ +type PlatformResetPasswordDefault struct { + _statusCode int + + Payload *PlatformResetPasswordDefaultBody +} + +// Code gets the status code for the platform reset password default response +func (o *PlatformResetPasswordDefault) Code() int { + return o._statusCode +} + +func (o *PlatformResetPasswordDefault) Error() string { + return fmt.Sprintf("[POST /v1/Platform/ResetPassword][%d] PlatformResetPassword default %+v", o._statusCode, o.Payload) +} + +func (o *PlatformResetPasswordDefault) GetPayload() *PlatformResetPasswordDefaultBody { + return o.Payload +} + +func (o *PlatformResetPasswordDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(PlatformResetPasswordDefaultBody) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +/*PlatformResetPasswordBody platform reset password body +swagger:model PlatformResetPasswordBody +*/ +type PlatformResetPasswordBody struct { + + // Existing Percona Platform user's email. + Email string `json:"email,omitempty"` +} + +// Validate validates this platform reset password body +func (o *PlatformResetPasswordBody) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (o *PlatformResetPasswordBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *PlatformResetPasswordBody) UnmarshalBinary(b []byte) error { + var res PlatformResetPasswordBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} + +/*PlatformResetPasswordDefaultBody platform reset password default body +swagger:model PlatformResetPasswordDefaultBody +*/ +type PlatformResetPasswordDefaultBody struct { + + // error + Error string `json:"error,omitempty"` + + // code + Code int32 `json:"code,omitempty"` + + // message + Message string `json:"message,omitempty"` + + // details + Details []*DetailsItems0 `json:"details"` +} + +// Validate validates this platform reset password default body +func (o *PlatformResetPasswordDefaultBody) Validate(formats strfmt.Registry) error { + var res []error + + if err := o.validateDetails(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *PlatformResetPasswordDefaultBody) validateDetails(formats strfmt.Registry) error { + + if swag.IsZero(o.Details) { // not required + return nil + } + + for i := 0; i < len(o.Details); i++ { + if swag.IsZero(o.Details[i]) { // not required + continue + } + + if o.Details[i] != nil { + if err := o.Details[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("PlatformResetPassword default" + "." + "details" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (o *PlatformResetPasswordDefaultBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *PlatformResetPasswordDefaultBody) UnmarshalBinary(b []byte) error { + var res PlatformResetPasswordDefaultBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} diff --git a/vendor/github.com/percona/pmm/api/serverpb/json/client/server/server_client.go b/vendor/github.com/percona/pmm/api/serverpb/json/client/server/server_client.go index ac5e54e3..e57a780b 100644 --- a/vendor/github.com/percona/pmm/api/serverpb/json/client/server/server_client.go +++ b/vendor/github.com/percona/pmm/api/serverpb/json/client/server/server_client.go @@ -37,6 +37,8 @@ type ClientService interface { Logs(params *LogsParams, writer io.Writer) (*LogsOK, error) + PlatformResetPassword(params *PlatformResetPasswordParams) (*PlatformResetPasswordOK, error) + PlatformSignIn(params *PlatformSignInParams) (*PlatformSignInOK, error) PlatformSignUp(params *PlatformSignUpParams) (*PlatformSignUpOK, error) @@ -217,6 +219,39 @@ func (a *Client) Logs(params *LogsParams, writer io.Writer) (*LogsOK, error) { return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* + PlatformResetPassword platforms reset password initiates password restore procedure +*/ +func (a *Client) PlatformResetPassword(params *PlatformResetPasswordParams) (*PlatformResetPasswordOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewPlatformResetPasswordParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "PlatformResetPassword", + Method: "POST", + PathPattern: "/v1/Platform/ResetPassword", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http", "https"}, + Params: params, + Reader: &PlatformResetPasswordReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + success, ok := result.(*PlatformResetPasswordOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*PlatformResetPasswordDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* PlatformSignIn platforms sign in links that PMM instance to percona platform user */