otp

package
v0.22.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package otp generates TOTP codes for GitHub 2FA automation in e2e tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnterTOTPCode

func EnterTOTPCode(page playwright.Page, secret string, logf func(string, ...any)) (bool, error)

EnterTOTPCode detects a GitHub TOTP input (#app_totp) on the current page, generates a code from the given secret, and enters it via simulated keystrokes. On the 2FA login page, GitHub auto-submits after 6 digits; on sudo pages, the submit button is clicked explicitly. If the first code is rejected, it retries once after waiting for the next TOTP period. Returns true if a TOTP form was found and submitted successfully. Returns (false, nil) if no TOTP input is visible.

func GenerateCode

func GenerateCode(secret string) (string, error)

GenerateCode produces a 6-digit TOTP code from a base32-encoded secret. If the current time is within 4 seconds of a 30-second period boundary, it sleeps until the next period to avoid generating a code that expires before the recipient can validate it.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL