Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions cornucopia.owasp.org/src/routes/rss.xml/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,13 @@ function generateDescription(post: Blogpost) {
}

function generateDate(post: Blogpost): string {
// Blogpost dates use the YYYYMMDD format (for example 20231201).
const date: string = post.date.toString();
const year = date.slice(0, 4);
const month = date.slice(4, 2);
const day = date.slice(6, 2);
const year = Number.parseInt(date.slice(0, 4), 10);
const month = Number.parseInt(date.slice(4, 6), 10);
const day = Number.parseInt(date.slice(6, 8), 10);

const d: Date = new Date();
d.setDate(Number.parseInt(day));
d.setMonth(Number.parseInt(month));
d.setFullYear(Number.parseInt(year));
const d: Date = new Date(Date.UTC(year, month - 1, day));
return d.toUTCString();
}

Expand Down
45 changes: 45 additions & 0 deletions cornucopia.owasp.org/src/routes/rss.xml/server.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';

const { getBlogposts } = vi.hoisted(() => ({
getBlogposts: vi.fn(),
}));

vi.mock('../../domain/blogpost/blogpostController.js', () => ({
getBlogposts,
}));

vi.mock('$lib/utils/cache.js', () => ({
LocalCache: vi.fn(async (load: () => unknown) => load()),
}));

vi.mock('$lib/utils/text.js', () => ({
Text: {
Format: (value: string) => value,
},
}));

import { GET } from './+server';

describe('GET /rss.xml', () => {
beforeEach(() => {
getBlogposts.mockReturnValue([
{
title: 'Test post',
path: 'test-post',
author: 'test-author',
markdown: '',
tags: ['test'],
hidden: false,
date: '20231201',
description: 'A test post',
},
]);
});

it('renders a valid RFC 822 pubDate', async () => {
const response = await GET();
const body = await response.text();

expect(body).toContain('<pubDate>Fri, 01 Dec 2023 00:00:00 GMT</pubDate>');
});
});
Loading