(t *testing.T)
| 35 | } |
| 36 | |
| 37 | func TestImageFileFailed(t *testing.T) { |
| 38 | logic.APIEndpoint = "http://127.0.0.1" |
| 39 | c := New() |
| 40 | defer c.Close() |
| 41 | c.Init(&logic.Options{DBUrl: "sqlite://?mode=memory"}) // nolint: errcheck |
| 42 | w := httptest.NewRecorder() |
| 43 | ctx, _ := gin.CreateTestContext(w) |
| 44 | ctx.Request, _ = http.NewRequest("GET", "/files/images/1234567890", nil) |
| 45 | c.handleImageDownload(ctx) |
| 46 | if w.Result().StatusCode != http.StatusUnauthorized { |
| 47 | t.Fatal("Check download token failed") |
| 48 | } |
| 49 | |
| 50 | tk, _ := model.ParseToken("EiJBQk9PNlRTSVhLU0VWSUpLWExEUVNVWFFSWFVBT1hHR1lZIgRjaGFuKgVNRlJHRzIUx5tXg-Vym58og7aZw05IkoDvse8..c2lnbg") // nolint: errcheck |
| 51 | w = httptest.NewRecorder() |
| 52 | ctx, _ = gin.CreateTestContext(w) |
| 53 | ctx.Request, _ = http.NewRequest("GET", "/files/images/1234567890", nil) |
| 54 | c.downloadImageFile(ctx, tk) |
| 55 | if w.Result().StatusCode != http.StatusUnauthorized { |
| 56 | t.Fatal("Check download url hash failed") |
| 57 | } |
| 58 | |
| 59 | tk, _ = model.ParseToken("EgMxMjMiBGNoYW4qBU1GUkdHMhTJH7dPQ2HFxdZCWt3RPyCM8SMJeQ..c2lnbg") // nolint: errcheck |
| 60 | w = httptest.NewRecorder() |
| 61 | ctx, _ = gin.CreateTestContext(w) |
| 62 | ctx.Request, _ = http.NewRequest("GET", "/files/images/1234567890", nil) |
| 63 | ctx.Request.URL.Path = "/files/images/1234567890" |
| 64 | c.downloadImageFile(ctx, tk) |
| 65 | if w.Result().StatusCode != http.StatusBadRequest { |
| 66 | t.Fatal("Check download image url hash failed") |
| 67 | } |
| 68 | |
| 69 | w = httptest.NewRecorder() |
| 70 | ctx, _ = gin.CreateTestContext(w) |
| 71 | ctx.Request, _ = http.NewRequest("GET", "/files/images/1234567890", nil) |
| 72 | ctx.Request.URL.Path = "/files/images/1234567890" |
| 73 | ctx.Params = []gin.Param{{Key: "fname", Value: "1234567890"}} |
| 74 | c.downloadImageFile(ctx, tk) |
| 75 | if w.Result().StatusCode != http.StatusNotFound { |
| 76 | t.Fatal("Check download image name failed") |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | func TestAudioFile(t *testing.T) { |
| 81 | fpath := filepath.Join(os.TempDir(), "files") |
nothing calls this directly
no test coverage detected