Skip to content

Commit

Permalink
Update version and include better mocking scenario for tests.
Browse files Browse the repository at this point in the history
Fix issues with matches being cancelled.

Update deps.

Update types for compiling.
  • Loading branch information
PhlexPlexico committed Dec 29, 2024
1 parent d953e82 commit eb54c26
Show file tree
Hide file tree
Showing 7 changed files with 1,816 additions and 2,129 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "g5api",
"version": "2.0.2.4",
"version": "2.0.2.5",
"private": true,
"type": "module",
"licenses": [
Expand Down Expand Up @@ -103,6 +103,7 @@
"@types/config": "^3.3.0",
"@types/express": "^4.17.17",
"@types/node": "^20.2.5",
"@types/passport": "^1.0.17",
"@types/steamapi": "^2.2.2",
"jest": "^29.5.0",
"jest-ts-webcompat-resolver": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/routes/matches/matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ router.put("/", Utils.ensureAuthenticated, async (req, res, next) => {
await db.query(sql, [matchRow[0].server_id]);

sql = "UPDATE `match` SET plugin_version = ? WHERE id = ?";
let get5Version = await newServer.getGet5Version();
let get5Version = await serverConn.getGet5Version();
await db.query(sql, [get5Version, matchRow[0].id]);
}
if (matchRow[0].is_pug != null && matchRow[0].is_pug == 1) {
Expand Down
10 changes: 1 addition & 9 deletions src/utility/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Strategy as SteamStrategy } from "passport-steam";
import passport from 'passport';
import { Strategy as LocalStrategy } from "passport-local";
import { hashSync, compare } from "bcrypt";
import user from "./mockProfile.js";
import MockStrategy from "./mockstrategy.js";
import {db} from "../services/db.js";
import { generate } from "randomstring";
Expand All @@ -25,16 +24,9 @@ passport.deserializeUser((obj, done) => {
function strategyForEnvironment() {
let strategy;
switch (process.env.NODE_ENV) {
// #TODO: Fix crashing while on dev environment. "cb is not a function" error. Discord @tshiken
case "test":
try {
const newUser = new user();
strategy = new MockStrategy({ name: "steam", user: newUser, passReqToCallback: true }, returnStrategy);
strategy = new MockStrategy({ name: "steam", passAuthentication: true }, returnStrategy);
break;
} catch (err) {
console.error(err);
}

default:
strategy = new SteamStrategy(
{
Expand Down
4 changes: 3 additions & 1 deletion src/utility/mockProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default class user {
{
value: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/d6/d6f3cfd2a1f5131863bbca13675412924cccc004_full.jpg",
}];
identifier = 'https://steamcommunity.com/openid/id/76561198025644194'
identifier = 'https://steamcommunity.com/openid/id/76561198025644194';
super_admin = 1;
admin = 1;
};
// export const id = "76561198025644194";
// export const displayName = "Phlex";
Expand Down
30 changes: 20 additions & 10 deletions src/utility/mockstrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@
*/
"use strict";

import { Strategy } from 'passport';
import {Strategy as OpenIDStrategy} from '@passport-next/passport-openid';
import { inherits } from 'util';
import user from "./mockProfile.js";

function MockStrategy(options, validate) {
options = options || {};
options.profile = (options.user === undefined) ? true : options.user;

function authenticate(req, identifier, profile, done) {
validate(req, identifier, profile, done);
}
this.name = 'steam';
function MockStrategy(options, verify) {
this.name = options.name;
this.passAuthentication = options.passAuthentication ? true : false;
this.userId = options.userId || 1;
this.verify = verify;
this.user = new user();
}

inherits(MockStrategy, Strategy);
inherits(MockStrategy, OpenIDStrategy);

MockStrategy.prototype.authenticate = function authenticate(req) {
if (this.passAuthentication) {
var self = this;
this.verify(this.user.id, this.user, function(identifier, profile, done) {
self.success(profile);
});
} else {
this.fail('Unauthorized');
}
}

export default MockStrategy;
1 change: 0 additions & 1 deletion src/utility/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { ID } from "@node-steam/id";
import {db} from "../services/db.js";
import { RowDataPacket } from 'mysql2';
import { NextFunction, Request, Response } from 'express';
import { Get5_OnRoundEnd } from '../types/map_flow/Get5_OnRoundEnd.js';
import { Get5_Player } from '../types/Get5_Player.js';

class Utils {
Expand Down
Loading

0 comments on commit eb54c26

Please sign in to comment.