-
-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: login and registration for sms
- Loading branch information
Showing
15 changed files
with
625 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/ory/mock | ||
|
||
go 1.22.1 | ||
|
||
require ( | ||
github.com/julienschmidt/httprouter v1.3.0 | ||
github.com/ory/graceful v0.1.3 | ||
) | ||
|
||
require github.com/pkg/errors v0.9.1 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= | ||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= | ||
github.com/ory/graceful v0.1.3 h1:FaeXcHZh168WzS+bqruqWEw/HgXWLdNv2nJ+fbhxbhc= | ||
github.com/ory/graceful v0.1.3/go.mod h1:4zFz687IAF7oNHHiB586U4iL+/4aV09o/PYLE34t2bA= | ||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= | ||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= | ||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"cmp" | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os" | ||
"sync" | ||
|
||
"github.com/julienschmidt/httprouter" | ||
|
||
"github.com/ory/graceful" | ||
) | ||
|
||
var ( | ||
documentsLock sync.RWMutex | ||
documents = make(map[string][]byte) | ||
) | ||
|
||
func main() { | ||
port := cmp.Or(os.Getenv("PORT"), "4471") | ||
server := graceful.WithDefaults(&http.Server{Addr: fmt.Sprintf(":%s", port)}) | ||
register(server) | ||
if err := graceful.Graceful(server.ListenAndServe, server.Shutdown); err != nil { | ||
log.Fatalln(err) | ||
} | ||
} | ||
|
||
func register(server *http.Server) { | ||
router := httprouter.New() | ||
|
||
router.GET("/health", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
_, _ = w.Write([]byte("OK")) | ||
}) | ||
|
||
router.GET("/documents/:id", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | ||
id := ps.ByName("id") | ||
|
||
documentsLock.RLock() | ||
doc, ok := documents[id] | ||
documentsLock.RUnlock() | ||
|
||
if ok { | ||
_, _ = w.Write(doc) | ||
Check warning Code scanning / CodeQL Reflected cross-site scripting Medium test
Cross-site scripting vulnerability due to
user-provided value Error loading related location Loading |
||
} else { | ||
w.WriteHeader(http.StatusNotFound) | ||
} | ||
}) | ||
|
||
router.PUT("/documents/:id", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | ||
documentsLock.Lock() | ||
defer documentsLock.Unlock() | ||
id := ps.ByName("id") | ||
|
||
body, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
documents[id] = body | ||
}) | ||
|
||
router.DELETE("/documents/:id", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | ||
documentsLock.Lock() | ||
defer documentsLock.Unlock() | ||
id := ps.ByName("id") | ||
|
||
delete(documents, id) | ||
w.WriteHeader(http.StatusNoContent) | ||
}) | ||
|
||
server.Handler = router | ||
} |
Oops, something went wrong.