completedTask, err = receptorClient.GetTask(taskGuid) Expect(err).NotTo(HaveOccurred()) return completedTask.State }).Should(Equal(receptor.TaskStateCompleted)) Expect(completedTask.Failed).To(BeTrue()) }) }) }) }) }) Context("Egress Rules", func() { var ( taskGuid string taskCreateRequest receptor.TaskCreateRequest ) BeforeEach(func() { taskGuid = helpers.GenerateGuid() taskCreateRequest = helpers.TaskCreateRequest( taskGuid, &models.RunAction{ User: "******", Path: "sh", Args: []string{ "-c", ` curl -s --connect-timeout 5 http://www.example.com -o /dev/null echo $? >> /tmp/result exit 0
}) It("serializes the completion callback URL", func() { Expect(serialization.TaskToResponse(task).CompletionCallbackURL).To(Equal("http://example.com/the-path")) }) }) Context("when the task doesn't have a CompletionCallbackURL", func() { It("leaves the completion callback URL blank", func() { Expect(serialization.TaskToResponse(task).CompletionCallbackURL).To(Equal("")) }) }) }) Describe("TaskFromRequest", func() { var request receptor.TaskCreateRequest var expectedTask models.Task BeforeEach(func() { request = receptor.TaskCreateRequest{ TaskGuid: "the-task-guid", Domain: "the-domain", RootFS: "the-rootfs", Action: &models.RunAction{ User: "******", Path: "the-path", }, MemoryMB: 100, DiskMB: 100, CPUWeight: 50, Privileged: true,
BeforeEach(func() { fakeBBS = new(fake_bbs.FakeReceptorBBS) logger = lager.NewLogger("test") logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.DEBUG)) responseRecorder = httptest.NewRecorder() handler = handlers.NewTaskHandler(fakeBBS, logger) }) Describe("Create", func() { validCreateRequest := receptor.TaskCreateRequest{ TaskGuid: "task-guid-1", Domain: "test-domain", RootFS: "docker://docker", Action: &models.RunAction{Path: "/bin/bash", Args: []string{"echo", "hi"}}, MemoryMB: 24, DiskMB: 12, CPUWeight: 10, LogGuid: "guid", LogSource: "source-name", ResultFile: "result-file", Annotation: "some annotation", Privileged: true, } expectedTask := models.Task{ TaskGuid: "task-guid-1", Domain: "test-domain", RootFS: "docker://docker", Action: &models.RunAction{Path: "/bin/bash", Args: []string{"echo", "hi"}}, MemoryMB: 24, DiskMB: 12, CPUWeight: 10,
runtime = ginkgomon.Invoke(grouper.NewParallel(os.Kill, grouper.Members{ {"rep", componentMaker.Rep("-allowPrivileged")}, {"converger", componentMaker.Converger()}, {"auctioneer", componentMaker.Auctioneer()}, {"router", componentMaker.Router()}, {"route-emitter", componentMaker.RouteEmitter()}, })) }) AfterEach(func() { helpers.StopProcesses(runtime) }) Context("when a task that tries to do privileged things is requested", func() { var taskRequest receptor.TaskCreateRequest BeforeEach(func() { taskRequest = helpers.TaskCreateRequest( helpers.GenerateGuid(), &models.RunAction{ Path: "sh", // always run as root; tests change task-level privileged User: "******", Args: []string{ "-c", // writing to /proc/sysrq-trigger requires full privileges; // h is a safe thing to write "echo h > /proc/sysrq-trigger", }, },
fakeClient *fake_bbs.FakeClient responseRecorder *httptest.ResponseRecorder handler *handlers.TaskHandler request *http.Request ) BeforeEach(func() { fakeClient = &fake_bbs.FakeClient{} logger = lager.NewLogger("test") logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.DEBUG)) responseRecorder = httptest.NewRecorder() handler = handlers.NewTaskHandler(fakeClient, logger) }) Describe("Create", func() { var validCreateRequest receptor.TaskCreateRequest var expectedTask *models.Task BeforeEach(func() { validCreateRequest = receptor.TaskCreateRequest{ TaskGuid: "task-guid-1", Domain: "test-domain", RootFS: "docker://docker", Action: models.WrapAction(&models.RunAction{User: "******", Path: "/bin/bash", Args: []string{"echo", "hi"}}), MemoryMB: 24, DiskMB: 12, CPUWeight: 10, LogGuid: "guid", LogSource: "source-name", ResultFile: "result-file", Annotation: "some annotation",