[feature] Implement /oauth/revoke for token revocation (#3983)

This commit is contained in:
tobi
2025-04-10 16:24:17 +02:00
committed by GitHub
parent b1a4d54c14
commit e032c959e1
8 changed files with 522 additions and 9 deletions

View File

@ -107,28 +107,40 @@ func (suite *AuthStandardTestSuite) TearDownTest() {
testrig.StopWorkers(&suite.state)
}
func (suite *AuthStandardTestSuite) newContext(requestMethod string, requestPath string, requestBody []byte, bodyContentType string) (*gin.Context, *httptest.ResponseRecorder) {
// create the recorder and gin test context
func (suite *AuthStandardTestSuite) newContext(
requestMethod string,
requestPath string,
requestBody []byte,
bodyContentType string,
) (*gin.Context, *httptest.ResponseRecorder) {
// Create the recorder and test context.
recorder := httptest.NewRecorder()
ctx, engine := testrig.CreateGinTestContext(recorder, nil)
// load templates into the engine
// Load templates into the engine.
testrig.ConfigureTemplatesWithGin(engine, "../../../web/template")
// create the request
// Create the request itself.
protocol := config.GetProtocol()
host := config.GetHost()
baseURI := fmt.Sprintf("%s://%s", protocol, host)
requestURI := fmt.Sprintf("%s/%s", baseURI, requestPath)
ctx.Request = httptest.NewRequest(
requestMethod,
requestURI,
bytes.NewReader(requestBody),
)
ctx.Request = httptest.NewRequest(requestMethod, requestURI, bytes.NewReader(requestBody)) // the endpoint we're hitting
ctx.Request.Header.Set("accept", "text/html")
// Transmit appropriate Content-Type.
if bodyContentType != "" {
ctx.Request.Header.Set("Content-Type", bodyContentType)
}
// trigger the session middleware on the context
// Accept whatever, so we can use
// this to test both HTML and JSON.
ctx.Request.Header.Set("accept", "*/*")
// Trigger the session middleware on the context.
store := memstore.NewStore(make([]byte, 32), make([]byte, 32))
store.Options(middleware.SessionOptions())
sessionMiddleware := sessions.Sessions("gotosocial-localhost", store)