Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/server/assets/codes/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</style>
</head>

<body id="home" class="tab-content">
<body id="codes-issue" class="tab-content">
{{template "navbar" .}}

<main role="main" class="container">
Expand Down
28 changes: 9 additions & 19 deletions internal/routes/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/google/exposure-notifications-verification-server/pkg/controller/admin"
"github.com/google/exposure-notifications-verification-server/pkg/controller/apikey"
"github.com/google/exposure-notifications-verification-server/pkg/controller/codes"
"github.com/google/exposure-notifications-verification-server/pkg/controller/home"
"github.com/google/exposure-notifications-verification-server/pkg/controller/issueapi"
"github.com/google/exposure-notifications-verification-server/pkg/controller/jwks"
"github.com/google/exposure-notifications-verification-server/pkg/controller/login"
Expand Down Expand Up @@ -188,24 +187,17 @@ func Server(
}
}

// TODO: this is a legacy path which is now duplicated on /codes
// This will be removed in a future release.
// Redirect old /home path to /codes/issue. This route is no longer in use,
// but the redirect is preserved in case people have their browser open to the
// old page.
//
// TODO: remove in 0.18+.
{
sub := r.PathPrefix("/home").Subrouter()
sub.Use(requireAuth)
sub.Use(loadCurrentRealm)
sub.Use(requireRealm)
sub.Use(processFirewall)
sub.Use(requireVerified)
sub.Use(requireMFA)
sub.Use(rateLimit)

homeController := home.New(ctx, cfg, db, h)
sub.Handle("", homeController.HandleHome()).Methods("GET")

// API for creating new verification codes. Called via AJAX.
issueapiController := issueapi.New(ctx, cfg, db, limiterStore, h)
sub.Handle("/issue", issueapiController.HandleIssue()).Methods("POST")
sub.Handle("", http.RedirectHandler("/codes/issue", http.StatusPermanentRedirect)).Methods("GET")
sub.Handle("/", http.RedirectHandler("/codes/issue", http.StatusPermanentRedirect)).Methods("GET")
sub.Handle("/issue", http.RedirectHandler("/codes/issue", http.StatusPermanentRedirect)).Methods("POST")
}

// codes
Expand All @@ -222,9 +214,6 @@ func Server(
sub.Handle("", http.RedirectHandler("/codes/issue", http.StatusSeeOther)).Methods("GET")
sub.Handle("/", http.RedirectHandler("/codes/issue", http.StatusSeeOther)).Methods("GET")

homeController := home.New(ctx, cfg, db, h)
sub.Handle("/issue", homeController.HandleHome()).Methods("GET")

// API for creating new verification codes. Called via AJAX.
issueapiController := issueapi.New(ctx, cfg, db, limiterStore, h)
sub.Handle("/issue", issueapiController.HandleIssue()).Methods("POST")
Expand Down Expand Up @@ -337,6 +326,7 @@ func Server(

// codesRoutes are the routes for checking codes.
func codesRoutes(r *mux.Router, c *codes.Controller) {
r.Handle("/issue", c.HandleIssue()).Methods("GET")
r.Handle("/status", c.HandleIndex()).Methods("GET")
r.Handle("/{uuid}", c.HandleShow()).Methods("GET")
r.Handle("/{uuid}/expire", c.HandleExpirePage()).Methods("PATCH")
Expand Down
41 changes: 6 additions & 35 deletions pkg/controller/home/home.go → pkg/controller/codes/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package home defines a web controller for the home page of the verification
// server. This view allows users to issue OTP codes and tie them to a diagnosis
// and test date.
package home
package codes

import (
"context"
"fmt"
"html/template"
"net/http"
"time"

"github.com/google/exposure-notifications-verification-server/pkg/config"
"github.com/google/exposure-notifications-verification-server/pkg/controller"
"github.com/google/exposure-notifications-verification-server/pkg/database"
"github.com/google/exposure-notifications-verification-server/pkg/render"
)

type Controller struct {
config *config.ServerConfig
db *database.Database
h *render.Renderer

pastDaysDuration time.Duration
displayAllowedDays string
}

// New creates a new controller for the home page.
func New(ctx context.Context, config *config.ServerConfig, db *database.Database, h *render.Renderer) *Controller {
pastDaysDuration := -1 * config.AllowedSymptomAge
displayAllowedDays := fmt.Sprintf("%.0f", config.AllowedSymptomAge.Hours()/24.0)

return &Controller{
config: config,
db: db,
h: h,

pastDaysDuration: pastDaysDuration,
displayAllowedDays: displayAllowedDays,
}
}

func (c *Controller) HandleHome() http.Handler {
func (c *Controller) HandleIssue() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand All @@ -81,9 +50,11 @@ func (c *Controller) HandleHome() http.Handler {

// Set test date params
now := time.Now().UTC()
pastDaysDuration := -1 * c.serverconfig.AllowedSymptomAge
displayAllowedDays := fmt.Sprintf("%.0f", c.serverconfig.AllowedSymptomAge.Hours()/24.0)
m["maxDate"] = now.Format("2006-01-02")
m["minDate"] = now.Add(c.pastDaysDuration).Format("2006-01-02")
m["maxSymptomDays"] = c.displayAllowedDays
m["minDate"] = now.Add(pastDaysDuration).Format("2006-01-02")
m["maxSymptomDays"] = displayAllowedDays
m["duration"] = realm.CodeDuration.Duration.String()
m["hasSMSConfig"] = hasSMSConfig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package home_test
package codes_test

import (
"context"
Expand All @@ -28,7 +28,7 @@ import (
"github.com/chromedp/chromedp"
)

func TestHandleHome_IssueCode(t *testing.T) {
func TestHandleIssue_IssueCode(t *testing.T) {
t.Parallel()

harness := envstest.NewServer(t)
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestHandleHome_IssueCode(t *testing.T) {
chromedp.Navigate(`http://`+harness.Server.Addr()+`/codes/issue`),

// Wait for render.
chromedp.WaitVisible(`body#home`, chromedp.ByQuery),
chromedp.WaitVisible(`body#codes-issue`, chromedp.ByQuery),

// Add a date fields
chromedp.SetValue(`input#test-date`, yesterday, chromedp.ByQuery),
Expand Down