diff --git a/api/api.go b/api/api.go index cd0f6e3104..fef53257ce 100644 --- a/api/api.go +++ b/api/api.go @@ -124,14 +124,6 @@ func (a *ApplicationHandler) BuildControlPlaneRoutes() *chi.Mux { handler := &handlers.Handler{A: a.A, RM: a.rm} - // TODO(subomi): left this here temporarily till the data plane is stable. - // Ingestion API. - router.Route("/ingest", func(ingestRouter chi.Router) { - ingestRouter.Use(middleware.RateLimiterHandler(a.A.Rate, a.cfg.ApiRateLimit)) - ingestRouter.Get("/{maskID}", a.HandleCrcCheck) - ingestRouter.Post("/{maskID}", a.IngestEvent) - }) - // Public API. router.Route("/api", func(v1Router chi.Router) { v1Router.Route("/v1", func(r chi.Router) { @@ -165,49 +157,6 @@ func (a *ApplicationHandler) BuildControlPlaneRoutes() *chi.Mux { }) }) - // TODO(subomi): left this here temporarily till the data plane is stable. - projectSubRouter.Route("/events", func(eventRouter chi.Router) { - eventRouter.Route("/", func(writeEventRouter chi.Router) { - eventRouter.With(middleware.Pagination).Get("/", handler.GetEventsPaged) - eventRouter.Get("/countbatchreplayevents", handler.CountAffectedEvents) - - // TODO(all): should the InstrumentPath change? - eventRouter.With(handler.RequireEnabledProject(), middleware.InstrumentPath(a.A.Licenser)).Post("/", handler.CreateEndpointEvent) - eventRouter.With(handler.RequireEnabledProject(), middleware.InstrumentPath(a.A.Licenser)).Post("/fanout", handler.CreateEndpointFanoutEvent) - eventRouter.With(handler.RequireEnabledProject(), middleware.InstrumentPath(a.A.Licenser)).Post("/broadcast", handler.CreateBroadcastEvent) - eventRouter.With(handler.RequireEnabledProject(), middleware.InstrumentPath(a.A.Licenser)).Post("/dynamic", handler.CreateDynamicEvent) - eventRouter.With(handler.RequireEnabledProject()).Post("/batchreplay", handler.BatchReplayEvents) - - eventRouter.Route("/{eventID}", func(eventSubRouter chi.Router) { - eventSubRouter.With(handler.RequireEnabledProject()).Put("/replay", handler.ReplayEndpointEvent) - eventSubRouter.Get("/", handler.GetEndpointEvent) - }) - }) - }) - - projectSubRouter.Route("/event-types", func(eventTypesRouter chi.Router) { - eventTypesRouter.Get("/", handler.GetEventTypes) - eventTypesRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateEventType) - eventTypesRouter.With(handler.RequireEnabledProject()).Put("/{eventTypeId}", handler.UpdateEventType) - eventTypesRouter.With(handler.RequireEnabledProject()).Post("/{eventTypeId}/deprecate", handler.DeprecateEventType) - }) - - projectSubRouter.Route("/eventdeliveries", func(eventDeliveryRouter chi.Router) { - eventDeliveryRouter.With(middleware.Pagination).Get("/", handler.GetEventDeliveriesPaged) - eventDeliveryRouter.With(handler.RequireEnabledProject()).Post("/forceresend", handler.ForceResendEventDeliveries) - eventDeliveryRouter.With(handler.RequireEnabledProject()).Post("/batchretry", handler.BatchRetryEventDelivery) - - eventDeliveryRouter.Route("/{eventDeliveryID}", func(eventDeliverySubRouter chi.Router) { - eventDeliverySubRouter.Get("/", handler.GetEventDelivery) - eventDeliverySubRouter.With(handler.RequireEnabledProject()).Put("/resend", handler.ResendEventDelivery) - - eventDeliverySubRouter.Route("/deliveryattempts", func(deliveryRouter chi.Router) { - deliveryRouter.Get("/", handler.GetDeliveryAttempts) - deliveryRouter.Get("/{deliveryAttemptID}", handler.GetDeliveryAttempt) - }) - }) - }) - projectSubRouter.Route("/subscriptions", func(subscriptionRouter chi.Router) { subscriptionRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateSubscription) subscriptionRouter.Post("/test_filter", handler.TestSubscriptionFilter) @@ -250,8 +199,6 @@ func (a *ApplicationHandler) BuildControlPlaneRoutes() *chi.Mux { }) }) - - // Dashboard API. router.Route("/ui", func(uiRouter chi.Router) { uiRouter.Use(middleware.JsonResponse) @@ -274,11 +221,11 @@ func (a *ApplicationHandler) BuildControlPlaneRoutes() *chi.Mux { authRouter.Post("/logout", handler.LogoutUser) }) - uiRouter.Route("/saml", func(samlRouter chi.Router) { - samlRouter.Use(middleware.RequireValidEnterpriseSSOLicense(handler.A.Licenser)) - samlRouter.Get("/login", handler.RedeemLoginSSOToken) - samlRouter.Get("/register", handler.RedeemRegisterSSOToken) - }) + uiRouter.Route("/saml", func(samlRouter chi.Router) { + samlRouter.Use(middleware.RequireValidEnterpriseSSOLicense(handler.A.Licenser)) + samlRouter.Get("/login", handler.RedeemLoginSSOToken) + samlRouter.Get("/register", handler.RedeemRegisterSSOToken) + }) uiRouter.Route("/users", func(userRouter chi.Router) { userRouter.Route("/{userID}", func(userSubRouter chi.Router) { @@ -350,48 +297,6 @@ func (a *ApplicationHandler) BuildControlPlaneRoutes() *chi.Mux { }) }) - // TODO(subomi): left this here temporarily till the data plane is stable. - projectSubRouter.Route("/events", func(eventRouter chi.Router) { - eventRouter.With(middleware.Pagination).Get("/", handler.GetEventsPaged) - eventRouter.Get("/countbatchreplayevents", handler.CountAffectedEvents) - - // TODO(all): should the InstrumentPath change? - eventRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateEndpointEvent) - eventRouter.With(handler.RequireEnabledProject()).Post("/fanout", handler.CreateEndpointFanoutEvent) - eventRouter.With(handler.RequireEnabledProject()).Post("/broadcast", handler.CreateBroadcastEvent) - eventRouter.With(handler.RequireEnabledProject()).Post("/dynamic", handler.CreateDynamicEvent) - eventRouter.With(handler.RequireEnabledProject()).Post("/batchreplay", handler.BatchReplayEvents) - - eventRouter.Route("/{eventID}", func(eventSubRouter chi.Router) { - eventSubRouter.With(handler.RequireEnabledProject()).Put("/replay", handler.ReplayEndpointEvent) - eventSubRouter.Get("/", handler.GetEndpointEvent) - }) - }) - - projectSubRouter.Route("/event-types", func(eventTypesRouter chi.Router) { - eventTypesRouter.Get("/", handler.GetEventTypes) - eventTypesRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateEventType) - eventTypesRouter.With(handler.RequireEnabledProject()).Put("/{eventTypeId}", handler.UpdateEventType) - eventTypesRouter.With(handler.RequireEnabledProject()).Post("/{eventTypeId}/deprecate", handler.DeprecateEventType) - }) - - projectSubRouter.Route("/eventdeliveries", func(eventDeliveryRouter chi.Router) { - eventDeliveryRouter.With(middleware.Pagination).Get("/", handler.GetEventDeliveriesPaged) - eventDeliveryRouter.With(handler.RequireEnabledProject()).Post("/forceresend", handler.ForceResendEventDeliveries) - eventDeliveryRouter.With(handler.RequireEnabledProject()).Post("/batchretry", handler.BatchRetryEventDelivery) - eventDeliveryRouter.Get("/countbatchretryevents", handler.CountAffectedEventDeliveries) - - eventDeliveryRouter.Route("/{eventDeliveryID}", func(eventDeliverySubRouter chi.Router) { - eventDeliverySubRouter.Get("/", handler.GetEventDelivery) - eventDeliverySubRouter.With(handler.RequireEnabledProject()).Put("/resend", handler.ResendEventDelivery) - - eventDeliverySubRouter.Route("/deliveryattempts", func(deliveryRouter chi.Router) { - deliveryRouter.Get("/", handler.GetDeliveryAttempts) - deliveryRouter.Get("/{deliveryAttemptID}", handler.GetDeliveryAttempt) - }) - }) - }) - projectSubRouter.Route("/subscriptions", func(subscriptionRouter chi.Router) { subscriptionRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateSubscription) subscriptionRouter.Post("/test_filter", handler.TestSubscriptionFilter) @@ -462,43 +367,6 @@ func (a *ApplicationHandler) BuildControlPlaneRoutes() *chi.Mux { endpointRouter.With(handler.CanManageEndpoint()).Put("/{endpointID}/expire_secret", handler.ExpireSecret) }) - // TODO(subomi): left this here temporarily till the data plane is stable. - portalLinkRouter.Route("/events", func(eventRouter chi.Router) { - eventRouter.Post("/", handler.CreateEndpointEvent) - eventRouter.With(middleware.Pagination).Get("/", handler.GetEventsPaged) - eventRouter.Post("/batchreplay", handler.BatchReplayEvents) - eventRouter.Get("/countbatchreplayevents", handler.CountAffectedEvents) - - eventRouter.Route("/{eventID}", func(eventSubRouter chi.Router) { - eventSubRouter.Get("/", handler.GetEndpointEvent) - eventSubRouter.Put("/replay", handler.ReplayEndpointEvent) - }) - }) - - portalLinkRouter.Route("/event-types", func(eventTypesRouter chi.Router) { - eventTypesRouter.Get("/", handler.GetEventTypes) - eventTypesRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateEventType) - eventTypesRouter.With(handler.RequireEnabledProject()).Put("/{eventTypeId}", handler.UpdateEventType) - eventTypesRouter.With(handler.RequireEnabledProject()).Post("/{eventTypeId}/deprecate", handler.DeprecateEventType) - }) - - portalLinkRouter.Route("/eventdeliveries", func(eventDeliveryRouter chi.Router) { - eventDeliveryRouter.With(middleware.Pagination).Get("/", handler.GetEventDeliveriesPaged) - eventDeliveryRouter.Post("/forceresend", handler.ForceResendEventDeliveries) - eventDeliveryRouter.Post("/batchretry", handler.BatchRetryEventDelivery) - eventDeliveryRouter.Get("/countbatchretryevents", handler.CountAffectedEventDeliveries) - - eventDeliveryRouter.Route("/{eventDeliveryID}", func(eventDeliverySubRouter chi.Router) { - eventDeliverySubRouter.Get("/", handler.GetEventDelivery) - eventDeliverySubRouter.Put("/resend", handler.ResendEventDelivery) - - eventDeliverySubRouter.Route("/deliveryattempts", func(deliveryRouter chi.Router) { - deliveryRouter.Get("/", handler.GetDeliveryAttempts) - deliveryRouter.Get("/{deliveryAttemptID}", handler.GetDeliveryAttempt) - }) - }) - }) - portalLinkRouter.Route("/subscriptions", func(subscriptionRouter chi.Router) { subscriptionRouter.Post("/", handler.CreateSubscription) subscriptionRouter.Post("/test_filter", handler.TestSubscriptionFilter) @@ -575,6 +443,13 @@ func (a *ApplicationHandler) BuildDataPlaneRoutes() *chi.Mux { }) }) + projectSubRouter.Route("/event-types", func(eventTypesRouter chi.Router) { + eventTypesRouter.Get("/", handler.GetEventTypes) + eventTypesRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateEventType) + eventTypesRouter.With(handler.RequireEnabledProject()).Put("/{eventTypeId}", handler.UpdateEventType) + eventTypesRouter.With(handler.RequireEnabledProject()).Post("/{eventTypeId}/deprecate", handler.DeprecateEventType) + }) + projectSubRouter.Route("/eventdeliveries", func(eventDeliveryRouter chi.Router) { eventDeliveryRouter.With(middleware.Pagination).Get("/", handler.GetEventDeliveriesPaged) eventDeliveryRouter.Post("/forceresend", handler.ForceResendEventDeliveries) @@ -595,8 +470,6 @@ func (a *ApplicationHandler) BuildDataPlaneRoutes() *chi.Mux { }) }) - - // Dashboard API. router.Route("/ui", func(uiRouter chi.Router) { uiRouter.Use(middleware.JsonResponse) @@ -612,11 +485,11 @@ func (a *ApplicationHandler) BuildDataPlaneRoutes() *chi.Mux { authRouter.Post("/logout", handler.LogoutUser) }) - uiRouter.Route("/saml", func(samlRouter chi.Router) { - samlRouter.Use(middleware.RequireValidEnterpriseSSOLicense(handler.A.Licenser)) - samlRouter.Get("/login", handler.RedeemLoginSSOToken) - samlRouter.Get("/register", handler.RedeemRegisterSSOToken) - }) + uiRouter.Route("/saml", func(samlRouter chi.Router) { + samlRouter.Use(middleware.RequireValidEnterpriseSSOLicense(handler.A.Licenser)) + samlRouter.Get("/login", handler.RedeemLoginSSOToken) + samlRouter.Get("/register", handler.RedeemRegisterSSOToken) + }) uiRouter.Route("/organisations", func(orgRouter chi.Router) { orgRouter.Route("/{orgID}", func(orgSubRouter chi.Router) { @@ -635,6 +508,13 @@ func (a *ApplicationHandler) BuildDataPlaneRoutes() *chi.Mux { }) }) + projectSubRouter.Route("/event-types", func(eventTypesRouter chi.Router) { + eventTypesRouter.Get("/", handler.GetEventTypes) + eventTypesRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateEventType) + eventTypesRouter.With(handler.RequireEnabledProject()).Put("/{eventTypeId}", handler.UpdateEventType) + eventTypesRouter.With(handler.RequireEnabledProject()).Post("/{eventTypeId}/deprecate", handler.DeprecateEventType) + }) + projectSubRouter.Route("/eventdeliveries", func(eventDeliveryRouter chi.Router) { eventDeliveryRouter.With(middleware.Pagination).Get("/", handler.GetEventDeliveriesPaged) eventDeliveryRouter.Post("/forceresend", handler.ForceResendEventDeliveries) diff --git a/api/dashboard_integration_test.go b/api/dashboard_integration_test.go index d0be32b3b1..cfcef123c9 100644 --- a/api/dashboard_integration_test.go +++ b/api/dashboard_integration_test.go @@ -1041,6 +1041,7 @@ type EventIntegrationTestSuite struct { suite.Suite DB database.Database Router http.Handler + DPRouter http.Handler ConvoyApp *ApplicationHandler AuthenticatorFn AuthenticatorFn DefaultOrg *datastore.Organisation @@ -1052,6 +1053,7 @@ func (s *EventIntegrationTestSuite) SetupSuite() { s.DB = getDB() s.ConvoyApp = buildServer() s.Router = s.ConvoyApp.BuildControlPlaneRoutes() + s.DPRouter = s.ConvoyApp.BuildDataPlaneRoutes() } func (s *EventIntegrationTestSuite) SetupTest() { @@ -1109,7 +1111,7 @@ func (s *EventIntegrationTestSuite) Test_CreateEndpointEvent() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1147,7 +1149,7 @@ func (s *EventIntegrationTestSuite) Test_CreateEndpointEvent_With_App_ID_Valid_E w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1171,7 +1173,7 @@ func (s *EventIntegrationTestSuite) Test_CreateEndpointEvent_Endpoint_is_disable w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1197,7 +1199,7 @@ func (s *EventIntegrationTestSuite) Test_GetEndpointEvent_Valid_Event() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1225,7 +1227,7 @@ func (s *EventIntegrationTestSuite) Test_ReplayEndpointEvent_Valid_Event() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1275,7 +1277,7 @@ func (s *EventIntegrationTestSuite) Test_GetEventDelivery_Valid_EventDelivery() w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1334,7 +1336,7 @@ func (s *EventIntegrationTestSuite) Test_ResendEventDelivery_Valid_Resend() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1376,7 +1378,7 @@ func (s *EventIntegrationTestSuite) Test_BatchRetryEventDelivery_Valid_EventDeli w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1412,7 +1414,7 @@ func (s *EventIntegrationTestSuite) Test_CountAffectedEventDeliveries_Valid_Filt w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1457,7 +1459,7 @@ func (s *EventIntegrationTestSuite) Test_ForceResendEventDeliveries_Valid_EventD w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1510,7 +1512,7 @@ func (s *EventIntegrationTestSuite) Test_GetEventsPaged() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1568,7 +1570,7 @@ func (s *EventIntegrationTestSuite) Test_GetEventDeliveriesPaged() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) diff --git a/api/ingest_integration_test.go b/api/ingest_integration_test.go index e1aa2cf6ac..824ff8b75d 100644 --- a/api/ingest_integration_test.go +++ b/api/ingest_integration_test.go @@ -27,6 +27,7 @@ type IngestIntegrationTestSuite struct { suite.Suite DB database.Database Router http.Handler + DPRouter http.Handler ConvoyApp *ApplicationHandler DefaultProject *datastore.Project } @@ -35,6 +36,7 @@ func (i *IngestIntegrationTestSuite) SetupSuite() { i.DB = getDB() i.ConvoyApp = buildServer() i.Router = i.ConvoyApp.BuildControlPlaneRoutes() + i.DPRouter = i.ConvoyApp.BuildDataPlaneRoutes() } func (i *IngestIntegrationTestSuite) SetupTest() { @@ -75,7 +77,7 @@ func (i *IngestIntegrationTestSuite) Test_IngestEvent_BadMaskID() { w := httptest.NewRecorder() // Act. - i.Router.ServeHTTP(w, req) + i.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(i.T(), expectedStatusCode, w.Code) @@ -104,7 +106,7 @@ func (i *IngestIntegrationTestSuite) Test_IngestEvent_NotHTTPSource() { w := httptest.NewRecorder() // Act. - i.Router.ServeHTTP(w, req) + i.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(i.T(), expectedStatusCode, w.Code) @@ -175,7 +177,7 @@ func (i *IngestIntegrationTestSuite) Test_IngestEvent_BadHmac() { w := httptest.NewRecorder() // Act. - i.Router.ServeHTTP(w, req) + i.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(i.T(), expectedStatusCode, w.Code) @@ -239,7 +241,7 @@ func (i *IngestIntegrationTestSuite) Test_IngestEvent_BadAPIKey() { w := httptest.NewRecorder() // Act. - i.Router.ServeHTTP(w, req) + i.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(i.T(), expectedStatusCode, w.Code) @@ -271,7 +273,7 @@ func (i *IngestIntegrationTestSuite) Test_IngestEvent_GoodBasicAuth() { w := httptest.NewRecorder() // Act. - i.Router.ServeHTTP(w, req) + i.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(i.T(), expectedStatusCode, w.Code) @@ -303,7 +305,7 @@ func (i *IngestIntegrationTestSuite) Test_IngestEvent_BadBasicAuth() { w := httptest.NewRecorder() // Act. - i.Router.ServeHTTP(w, req) + i.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(i.T(), expectedStatusCode, w.Code) @@ -330,7 +332,7 @@ func (i *IngestIntegrationTestSuite) Test_IngestEvent_NoopVerifier() { w := httptest.NewRecorder() // Act. - i.Router.ServeHTTP(w, req) + i.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(i.T(), expectedStatusCode, w.Code) @@ -358,7 +360,7 @@ func (i *IngestIntegrationTestSuite) Test_IngestEvent_NoopVerifier_EmptyRequestB w := httptest.NewRecorder() // Act. - i.Router.ServeHTTP(w, req) + i.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(i.T(), expectedStatusCode, w.Code) @@ -393,7 +395,7 @@ func (i *IngestIntegrationTestSuite) Test_IngestEvent_PayloadExceedsConfiguredPa w := httptest.NewRecorder() // Act. - i.Router.ServeHTTP(w, req) + i.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(i.T(), http.StatusRequestEntityTooLarge, w.Code) diff --git a/api/portal_api_integration_test.go b/api/portal_api_integration_test.go index eba4ca47a0..a350e551fd 100644 --- a/api/portal_api_integration_test.go +++ b/api/portal_api_integration_test.go @@ -27,6 +27,7 @@ type PortalEndpointIntegrationTestSuite struct { suite.Suite DB database.Database Router http.Handler + DPRouter http.Handler ConvoyApp *ApplicationHandler DefaultOrg *datastore.Organisation DefaultProject *datastore.Project @@ -39,6 +40,7 @@ func (s *PortalEndpointIntegrationTestSuite) SetupSuite() { s.DB = getDB() s.ConvoyApp = buildServer() s.Router = s.ConvoyApp.BuildControlPlaneRoutes() + s.DPRouter = s.ConvoyApp.BuildDataPlaneRoutes() } func (s *PortalEndpointIntegrationTestSuite) SetupTest() { @@ -178,6 +180,7 @@ type PortalEventIntegrationTestSuite struct { suite.Suite DB database.Database Router http.Handler + DPRouter http.Handler ConvoyApp *ApplicationHandler DefaultProject *datastore.Project APIKey string @@ -187,6 +190,7 @@ func (s *PortalEventIntegrationTestSuite) SetupSuite() { s.DB = getDB() s.ConvoyApp = buildServer() s.Router = s.ConvoyApp.BuildControlPlaneRoutes() + s.DPRouter = s.ConvoyApp.BuildDataPlaneRoutes() } func (s *PortalEventIntegrationTestSuite) SetupTest() { @@ -243,7 +247,7 @@ func (s *PortalEventIntegrationTestSuite) Test_GetEndpointEvent_Valid_Event() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -270,7 +274,7 @@ func (s *PortalEventIntegrationTestSuite) Test_ReplayEndpointEvent_Valid_Event() w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -319,7 +323,7 @@ func (s *PortalEventIntegrationTestSuite) Test_GetEventDelivery_Valid_EventDeliv w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -328,6 +332,10 @@ func (s *PortalEventIntegrationTestSuite) Test_GetEventDelivery_Valid_EventDeliv var respEventDelivery datastore.EventDelivery parseResponse(s.T(), w.Result(), &respEventDelivery) require.Equal(s.T(), eventDelivery.UID, respEventDelivery.UID) + + w = httptest.NewRecorder() + s.Router.ServeHTTP(w, req) + require.Equal(s.T(), http.StatusNotFound, w.Code) } func (s *PortalEventIntegrationTestSuite) Test_GetEventDelivery_Event_not_found() { @@ -377,7 +385,7 @@ func (s *PortalEventIntegrationTestSuite) Test_ResendEventDelivery_Valid_Resend( w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -387,6 +395,10 @@ func (s *PortalEventIntegrationTestSuite) Test_ResendEventDelivery_Valid_Resend( parseResponse(s.T(), w.Result(), &respEventDelivery) require.Equal(s.T(), datastore.ScheduledEventStatus, respEventDelivery.Status) require.Equal(s.T(), eventDelivery.UID, respEventDelivery.UID) + + w = httptest.NewRecorder() + s.Router.ServeHTTP(w, req) + require.Equal(s.T(), http.StatusNotFound, w.Code) } func (s *PortalEventIntegrationTestSuite) Test_BatchRetryEventDelivery_Valid_EventDeliveries() { @@ -418,10 +430,14 @@ func (s *PortalEventIntegrationTestSuite) Test_BatchRetryEventDelivery_Valid_Eve w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) + + w = httptest.NewRecorder() + s.Router.ServeHTTP(w, req) + require.Equal(s.T(), http.StatusNotFound, w.Code) } func (s *PortalEventIntegrationTestSuite) Test_CountAffectedEventDeliveries_Valid_Filters() { @@ -453,7 +469,7 @@ func (s *PortalEventIntegrationTestSuite) Test_CountAffectedEventDeliveries_Vali w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -464,6 +480,10 @@ func (s *PortalEventIntegrationTestSuite) Test_CountAffectedEventDeliveries_Vali } parseResponse(s.T(), w.Result(), &num) require.Equal(s.T(), 3, num.Num) + + w = httptest.NewRecorder() + s.Router.ServeHTTP(w, req) + require.Equal(s.T(), http.StatusNotFound, w.Code) } func (s *PortalEventIntegrationTestSuite) Test_ForceResendEventDeliveries_Valid_EventDeliveries() { @@ -497,7 +517,7 @@ func (s *PortalEventIntegrationTestSuite) Test_ForceResendEventDeliveries_Valid_ w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -507,6 +527,10 @@ func (s *PortalEventIntegrationTestSuite) Test_ForceResendEventDeliveries_Valid_ require.NoError(s.T(), err) require.Equal(s.T(), expectedMessage, response["message"].(string)) + + w = httptest.NewRecorder() + s.Router.ServeHTTP(w, req) + require.Equal(s.T(), http.StatusNotFound, w.Code) } func (s *PortalEventIntegrationTestSuite) Test_GetEventsPaged() { @@ -549,7 +573,7 @@ func (s *PortalEventIntegrationTestSuite) Test_GetEventsPaged() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -606,7 +630,7 @@ func (s *PortalEventIntegrationTestSuite) Test_GetEventDeliveriesPaged() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -621,6 +645,10 @@ func (s *PortalEventIntegrationTestSuite) Test_GetEventDeliveriesPaged() { for i, delivery := range v { require.Equal(s.T(), respEvents[i].UID, delivery.UID) } + + w = httptest.NewRecorder() + s.Router.ServeHTTP(w, req) + require.Equal(s.T(), http.StatusNotFound, w.Code) } func TestPortalEventIntegrationTestSuite(t *testing.T) { diff --git a/api/public_integration_test.go b/api/public_integration_test.go index 643ae75c91..b18c1640ad 100644 --- a/api/public_integration_test.go +++ b/api/public_integration_test.go @@ -656,6 +656,7 @@ type PublicEventIntegrationTestSuite struct { suite.Suite DB database.Database Router http.Handler + DPRouter http.Handler ConvoyApp *ApplicationHandler DefaultProject *datastore.Project APIKey string @@ -665,6 +666,7 @@ func (s *PublicEventIntegrationTestSuite) SetupSuite() { s.DB = getDB() s.ConvoyApp = buildServer() s.Router = s.ConvoyApp.BuildControlPlaneRoutes() + s.DPRouter = s.ConvoyApp.BuildDataPlaneRoutes() } func (s *PublicEventIntegrationTestSuite) SetupTest() { @@ -716,7 +718,7 @@ func (s *PublicEventIntegrationTestSuite) Test_CreateEndpointEvent() { req := createRequest(http.MethodPost, url, s.APIKey, body) w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -751,7 +753,7 @@ func (s *PublicEventIntegrationTestSuite) Test_CreateDynamicEvent() { req := createRequest(http.MethodPost, url, s.APIKey, body) w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -781,7 +783,7 @@ func (s *PublicEventIntegrationTestSuite) Test_CreateBroadcastEvent() { req := createRequest(http.MethodPost, url, s.APIKey, body) w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -803,7 +805,7 @@ func (s *PublicEventIntegrationTestSuite) Test_CreateFanoutEvent_MultipleEndpoin req := createRequest(http.MethodPost, url, s.APIKey, body) w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -837,7 +839,7 @@ func (s *PublicEventIntegrationTestSuite) Test_CreateEndpointEvent_With_App_ID_V req := createRequest(http.MethodPost, url, s.APIKey, body) w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -857,7 +859,7 @@ func (s *PublicEventIntegrationTestSuite) Test_CreateEndpointEvent_Endpoint_is_d req := createRequest(http.MethodPost, url, s.APIKey, body) w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -879,7 +881,7 @@ func (s *PublicEventIntegrationTestSuite) Test_GetEndpointEvent_Valid_Event() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -903,7 +905,7 @@ func (s *PublicEventIntegrationTestSuite) Test_ReplayEndpointEvent_Valid_Event() w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -945,7 +947,7 @@ func (s *PublicEventIntegrationTestSuite) Test_GetEventDelivery_Valid_EventDeliv w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1016,7 +1018,7 @@ func (s *PublicEventIntegrationTestSuite) Test_ResendEventDelivery_Valid_Resend( w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1054,7 +1056,7 @@ func (s *PublicEventIntegrationTestSuite) Test_BatchRetryEventDelivery_Valid_Eve w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1088,7 +1090,7 @@ func (s *PublicEventIntegrationTestSuite) Test_ForceResendEventDeliveries_Valid_ w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1137,7 +1139,7 @@ func (s *PublicEventIntegrationTestSuite) Test_GetEventsPaged() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -1203,7 +1205,7 @@ func (s *PublicEventIntegrationTestSuite) Test_GetEventDeliveriesPaged() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -2778,6 +2780,7 @@ type PublicEventTypeIntegrationTestSuite struct { suite.Suite DB database.Database Router http.Handler + DPRouter http.Handler ConvoyApp *ApplicationHandler DefaultOrg *datastore.Organisation DefaultProject *datastore.Project @@ -2788,6 +2791,7 @@ func (s *PublicEventTypeIntegrationTestSuite) SetupSuite() { s.DB = getDB() s.ConvoyApp = buildServer() s.Router = s.ConvoyApp.BuildControlPlaneRoutes() + s.DPRouter = s.ConvoyApp.BuildDataPlaneRoutes() } func (s *PublicEventTypeIntegrationTestSuite) SetupTest() { @@ -2811,6 +2815,12 @@ func (s *PublicEventTypeIntegrationTestSuite) SetupTest() { } _, s.APIKey, _ = testdb.SeedAPIKey(s.ConvoyApp.A.DB, role, "", "test", "", "") + + apiRepo := postgres.NewAPIKeyRepo(s.ConvoyApp.A.DB, nil) + userRepo := postgres.NewUserRepo(s.ConvoyApp.A.DB, nil) + + portalLinkRepo := postgres.NewPortalLinkRepo(s.ConvoyApp.A.DB, s.ConvoyApp.A.Cache) + initRealmChain(s.T(), apiRepo, userRepo, portalLinkRepo, s.ConvoyApp.A.Cache) } func (s *PublicEventTypeIntegrationTestSuite) TearDownTest() { @@ -2831,7 +2841,7 @@ func (s *PublicEventTypeIntegrationTestSuite) Test_GetEventTypes() { require.NoError(s.T(), err) // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -2857,7 +2867,7 @@ func (s *PublicEventTypeIntegrationTestSuite) Test_CreateEventType() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -2887,7 +2897,7 @@ func (s *PublicEventTypeIntegrationTestSuite) Test_UpdateEventType() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code) @@ -2916,7 +2926,7 @@ func (s *PublicEventTypeIntegrationTestSuite) Test_DeprecateEventType() { w := httptest.NewRecorder() // Act. - s.Router.ServeHTTP(w, req) + s.DPRouter.ServeHTTP(w, req) // Assert. require.Equal(s.T(), expectedStatusCode, w.Code)