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

Version 2.0.2.5 #297

Merged
merged 2 commits into from
Dec 29, 2024
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
4 changes: 2 additions & 2 deletions 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,12 +103,12 @@
"@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",
"jsdoc": "^4.0.2",
"nodemon": "^2.0.22",
"passport-mock-strategy": "^2.0.0",
"redis-mock": "^0.56.3",
"supertest": "^6.3.3",
"ts-jest": "^29.1.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
8 changes: 5 additions & 3 deletions src/utility/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { Strategy as SteamStrategy } from "passport-steam";
import passport from 'passport';
import { Strategy as LocalStrategy } from "passport-local";
import { hashSync, compare } from "bcrypt";
import MockStrategy from "passport-mock-strategy";
import user from "./mockProfile.js";
import MockStrategy from "./mockstrategy.js";
import {db} from "../services/db.js";
import { generate } from "randomstring";
import Utils from "./utils.js";
Expand All @@ -25,7 +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":
strategy = new MockStrategy({ name: "steam", passAuthentication: true }, returnStrategy);
break;
default:
strategy = new SteamStrategy(
{
Expand Down Expand Up @@ -128,6 +129,7 @@ async function returnStrategy(identifier, profile, done) {
api_key: curUser[0].id + ":" + Utils.decrypt(curUser[0].api_key),
});
} catch (err) {
console.log(profile.toString());
console.log(
"ERRORERRORERRORERRORERRORERRORERRORERROR " +
err +
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
55 changes: 30 additions & 25 deletions src/utility/mockstrategy.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import { Strategy as _Strategy } from "passport-strategy";
import { inherits } from "util"; // The reply from Github OAuth2
/**
* Author: Michael Weibel <michael.weibel@gmail.com>
* License: MIT
*/
"use strict";

import {Strategy as OpenIDStrategy} from '@passport-next/passport-openid';
import { inherits } from 'util';
import user from "./mockProfile.js";
class MockStrategy extends _Strategy{
constructor(name, strategyCallback) {
super(name);


if (!name || !name.length) {
throw new TypeError("DevStrategy requires a Strategy name");
}

_Strategy.call(this);
this.name = name;
this._identifier = user;
// Callback supplied to OAuth2 strategies handling verification
this._cb = strategyCallback;
}
authenticate() {
this._cb(null, this._identifier, (error, user) => {
this.success(user);
});
}

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();
}
export {
MockStrategy as default
};

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
Loading