Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support external clock mocking. #17

Merged
merged 2 commits into from
Oct 31, 2020
Merged

Support external clock mocking. #17

merged 2 commits into from
Oct 31, 2020

Conversation

kisom
Copy link
Member

@kisom kisom commented Dec 10, 2018

No description provided.

@kisom kisom requested a review from qbit December 10, 2018 06:02
@kisom kisom mentioned this pull request Dec 10, 2018
@@ -15,7 +15,7 @@ import (
"github.com/benbjohnson/clock"
)

var time clock.Clock
var timeSource = clock.New()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that this would be muc better on the otp struct rather than a global.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to jump in randomly, but without this patch, twofactor is broken and as a consequence browserpass is broken and OTP doesn't work for me on Firefox :D

@colemickens it can't be a field in the struct because the current twofactor API does not require any instantiation. You can just call twofactor.FromURL(url), so the otp struct's field would be uninitialised.

@kisom can we get this PR merged? If you'll accept my random PR approvals, LGTM :)

@@ -166,3 +166,7 @@ func totpFromURL(u *url.URL) (*TOTP, string, error) {
func (otp *TOTP) QR(label string) ([]byte, error) {
return otp.OATH.QR(otp.Type(), label)
}

func SetClock(c clock.Clock) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then this could be func (otp *TOTP) SetClock(c clock.Clock) { ... }.

Copy link
Collaborator

@qbit qbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@qbit
Copy link
Collaborator

qbit commented Feb 15, 2019

@colemickens could you create a new PR with your suggestions?

@kisom kisom merged commit 0857b29 into master Oct 31, 2020
@kisom kisom deleted the kyle/mock-clock branch October 31, 2020 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants