Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #265

Merged
merged 6 commits into from
Aug 13, 2023
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
23 changes: 23 additions & 0 deletions src/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,30 @@ def scrape_series(self,
manga_id, feed_url):
manga_ids.add(manga_id)
chapter_ids.extend(res)

elif res is None:
errors += 1
logger.error(f'Failed to scrape series {title_id} {manga_id}')

ms = scraper.dbutil.get_manga_service(service_id, title_id)

# release_interval actually gets set after this function is called, but it is likely that it has already been set before
# as this feature requires manual configuration. That's why it should be ok to use it here even if it is the old value.
if not ms.disabled and (ms.next_update is None or ms.next_update < utcnow()):
if ms.release_interval is None:
logger.warning(f'Release interval is None for manga {title_id} on service {service_id}. Disabling automatic updates for it.')
scraper.dbutil.execute('UPDATE manga_service SET disabled=TRUE WHERE service_id = %s AND manga_id = %s', (service_id, manga_id))
else:
# If all ok set latest release and refetch manga_service to get the updated latest_release
scraper.dbutil.update_latest_release([manga_id])
ms = scraper.dbutil.get_manga_service(service_id, title_id)

next_date = ms.latest_release + ms.release_interval
if next_date < utcnow():
next_date = utcnow() + ms.release_interval

scraper.dbutil.update_manga_next_update(service_id, manga_id, next_date + timedelta(minutes=10))

except psycopg.Error:
logger.exception(f'Database error while updating manga {title_id} on service {service_id}')
scraper.dbutil.update_manga_next_update(service_id, manga_id, scraper.next_update())
Expand All @@ -186,6 +207,8 @@ def scrape_series(self,
scraper.dbutil.update_manga_next_update(service_id, manga_id, scraper.next_update())
errors += 1

scraper.dbutil.set_manga_last_checked(service_id, manga_id, utcnow())

if errors > 1:
break

Expand Down
2 changes: 1 addition & 1 deletion src/scrapers/base_rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def add_from_feed_url(self, service_id: int, feed_url: str) -> Optional[ScrapeSe
if entries is None:
return None

return self.handle_adding_chapters(entries, service_id)
return self.handle_adding_chapters(entries, service_id) or ScrapeServiceRetVal()

def scrape_service(self, service_id: int, feed_url: str,
last_update: Optional[datetime],
Expand Down
6 changes: 3 additions & 3 deletions src/utils/dbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,12 +715,12 @@ def get_mangas_for_notifications(self, manga_ids: List[int], *, cur: Cursor = No
return list(map(MangaForNotifications.parse_obj, cur))

@optional_transaction()
def update_latest_release(self, data: List[int], *, cur: Cursor = NotImplemented) -> None:
format_ids = self.get_format_args(data)
def update_latest_release(self, manga_ids: List[int], *, cur: Cursor = NotImplemented) -> None:
format_ids = self.get_format_args(manga_ids)
sql = 'UPDATE manga m SET latest_release=c.release_date FROM ' \
f'(SELECT MAX(release_date), manga_id FROM chapters WHERE manga_id IN ({format_ids}) GROUP BY manga_id) as c(release_date, manga_id)' \
'WHERE m.manga_id=c.manga_id'
cur.execute(sql, data)
cur.execute(sql, manga_ids)

@overload
@optional_transaction()
Expand Down
129 changes: 0 additions & 129 deletions web/cypress/e2e/auth.cy.ts

This file was deleted.

51 changes: 51 additions & 0 deletions web/cypress/e2e/auth/auth.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { normalUser } from '../../../__tests__/constants';

describe('Test authentication', () => {
it('Logs in with correct email + password', () => {
cy.task('flushRedis');
cy.visit('/');
cy.findByText(/^recent releases$/i);

cy.findByRole('button', { name: /login/i }).click();

cy.findByRole('textbox', { name: /email address/i }).type(normalUser.email);
cy.findByLabelText(/password/i).type(normalUser.password);
cy.findByRole('button', { name: /^sign in$/i }).click();
cy.findByText(/^recent releases \(for your follows\)/i);
});

it('Ratelimits after 3 failed login attempts', () => {
cy.task('flushRedis');

const login = () => {
cy.visit('/login');
cy.findByRole('textbox', { name: /email address/i }).clear().type(normalUser.email);
cy.findByLabelText(/password/i).type('aaaaaaaaa');
cy.findByRole('button', { name: /^sign in$/i }).click();
};

for (let i = 0; i < 2; i++) {
login();
if (i === 0) {
cy.findByRole('alert');
cy.findByText(/^sign in failed/i);
}
}

// This should not reset the rate limiting
cy.login(normalUser);
cy.logout();

login();

cy.url().should('include', '/login');

// 4th time should rate limit
login();

cy.url().should('include', '/api/auth/error?error=Ratelimited.%20Try%20again%20later');

cy.task('flushRedis');
});
});

85 changes: 85 additions & 0 deletions web/cypress/e2e/auth/data-management.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { CreatedUser } from '../../types';
import { nextAuthSessionCookie } from '../../constants';

describe('Account data management', () => {
describe('Request account data', () => {
it('is possible to download your data', () => {
cy.task('flushRedis');

// Create a new user and log in
cy.task<CreatedUser>('createUser')
.then(user => {
cy.wrap(user).as('user');
});

cy.get<CreatedUser>('@user')
.then((user) => cy.login(user));

// Go to profile page
cy.findByRole('button', { name: /account of current user/i }).click();
cy.findByRole('menuitem', { name: /^profile$/i }).click();
cy.findByRole('button', { name: /Download a copy of personal data/i }).click();

cy.intercept({
pathname: '/api/user/dataRequest',
method: 'POST',
}, (req) => {
req.redirect('/profile');
}).as('userData');

// Initiate data download
cy.findByRole('button', { name: /proceed/i }).click();

cy.wait('@userData').its('request').then((req) => {
cy.request(req)
.then(({ body, headers }) => {
expect(headers).to.have.property('content-disposition', 'attachment; filename="manga-tracker-user-data.json"');
expect(body).to.include.keys(['user', 'accounts', 'sessions', 'notifications', 'follows']);
});
});
});
});

describe('Delete account', () => {
it('is possible to delete your own account', () => {
cy.task('flushRedis');

// Create a new user and log in
cy.task<CreatedUser>('createUser')
.then(user => {
cy.wrap(user).as('user');
});

cy.get<CreatedUser>('@user')
.then((user) => cy.login(user));

// Go to profile page
cy.findByRole('button', { name: /account of current user/i }).click();
cy.findByRole('menuitem', { name: /^profile$/i }).click();
cy.findByRole('button', { name: /delete account/i }).click();

// Initiate account deletion
cy.findByRole('button', { name: /delete account/i }).should('be.disabled');

cy.get<CreatedUser>('@user')
.then((user) => {
cy.findByText(new RegExp(`Type "${user.username}" to acknowledge this`));
cy.findByRole('textbox').type(user.username);
});

cy.findByRole('button', { name: /delete account/i }).click();

cy.url().should('include', '/login');
cy.getCookie(nextAuthSessionCookie).should('be.null');

// Trying to log in again with the deleted account should fail
cy.get<CreatedUser>('@user')
.then((user) => cy.login(user, true));

cy.findByRole('alert');
cy.findByText(/^sign in failed/i);

cy.task('flushRedis');
});
});
});
15 changes: 15 additions & 0 deletions web/cypress/e2e/auth/login-features.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { normalUser } from '../../../__tests__/constants';

describe('Login redirect works', () => {
it.only('Redirects back to /manga/1 after logging in', () => {
cy.task('flushRedis');
cy.visit('/manga/1');

cy.findByRole('button', { name: /login/i }).click();

cy.findByRole('textbox', { name: /email address/i }).type(normalUser.email);
cy.findByLabelText(/password/i).type(normalUser.password);
cy.findByRole('button', { name: /^sign in$/i }).click();
cy.url().should('contain', '/manga/1');
});
});
3 changes: 1 addition & 2 deletions web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ export default async (phase, { defaultConfig }) => {
if (/true|y|yes/i.test(process.env.CYPRESS || '')) {
conf.experimental = {
swcPlugins: [
// Currently broken with latest nextjs version
// ['swc-plugin-coverage-instrument', {}],
['swc-plugin-coverage-instrument', {}],
],
};
}
Expand Down
Loading