Skip to content

Commit

Permalink
Merge pull request #1431 from mosen/hotfix/unit_test_403_authz
Browse files Browse the repository at this point in the history
Hotfix/unit test 403 authz
  • Loading branch information
mosen authored Jan 7, 2022
2 parents eb045e1 + 098bc90 commit 5dba346
Show file tree
Hide file tree
Showing 41 changed files with 308 additions and 200 deletions.
19 changes: 0 additions & 19 deletions app/Console/Commands/FakerDataStore.php

This file was deleted.

11 changes: 11 additions & 0 deletions app/Http/Controllers/Api/ModulesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class ModulesController extends Controller
{
//
}
3 changes: 3 additions & 0 deletions app/Machine.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
namespace App;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use MR\Scopes\CreatedSinceScope;
use munkireport\models\MRModel;

class Machine extends MRModel
{
use HasFactory;

protected $table = 'machine';

protected $fillable = [
Expand Down
3 changes: 3 additions & 0 deletions app/MachineGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

Expand All @@ -13,6 +14,8 @@
*/
class MachineGroup extends Model
{
use HasFactory;

protected $fillable = [
'name',
'business_unit_id'
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function boot()
Log::debug('global admin gate accepted user: ' . $user->email . ', has role');
return true;
} else {
Log::debug('global admin gate rejected user: ' . $user->email . ', not in any role(s) that have archive');
Log::debug('global admin gate rejected user: ' . $user->email . ', has role `' . $user->role . '` which is not in any authorized role(s) (' . implode(', ', $globalAdmins) . ')');
return false;
}
});
Expand Down
3 changes: 3 additions & 0 deletions app/ReportData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace App;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Scopes\NotUpdatedForScope;
use App\Scopes\UpdatedBetweenScope;
Expand All @@ -11,6 +12,8 @@

class ReportData extends MRModel
{
use HasFactory;

/**
* @inheritDoc
*/
Expand Down
3 changes: 2 additions & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Contracts\Translation\HasLocalePreference;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
Expand All @@ -18,7 +19,7 @@

class User extends Authenticatable implements LegacyUser, HasLocalePreference
{
use HasApiTokens, Notifiable;
use HasApiTokens, Notifiable, HasFactory;

/**
* The attributes that are mass assignable.
Expand Down
3 changes: 3 additions & 0 deletions app/UserContactMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class UserContactMethod extends Model
{
use HasFactory;

protected $table = 'users_contact_methods';

protected $fillable = [
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@
},
"autoload": {
"classmap": [
"app/Console/Commands/FakerDataStore.php",
"database/seeds",
"database/factories"
"app/Console/Commands/FakerDataStore.php"
],
"files": [
"app/helpers/bootstrap_helper.php",
Expand All @@ -131,6 +129,8 @@
"munkireport\\processors\\": "app/processors/",
"munkireport\\builders\\": "database/builders/",
"munkireport\\lib\\": "app/lib/munkireport",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/",
"Tests\\": "tests/",
"App\\": "app/",
"MR\\": "MR/"
Expand Down
89 changes: 50 additions & 39 deletions database/factories/MachineFactory.php
Original file line number Diff line number Diff line change
@@ -1,45 +1,56 @@
<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(\App\Machine::class, function (Faker\Generator $faker) {
namespace Database\Factories;

$oses = [
['101206', '16G29'],
['101301', '17B48'],
['101503', '19D76'],
];
use Illuminate\Database\Eloquent\Factories\Factory;

// Allow standalone
try {
list($modelcode, $machine_name, $machine_model, $machine_desc) = FakerDataStore::get('machine_factory', 'machine');
} catch (\Throwable $th) {
list($modelcode, $machine_name, $machine_model, $machine_desc) = ['P7QM', 'MacPro', 'MacPro7,1', 'Mac Pro (2019)'];
}

list($os_version, $build) = $faker->randomElement($oses);
class MachineFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$oses = [
['101206', '16G29'],
['101301', '17B48'],
['101503', '19D76'],
];

// Allow standalone
// try {
// list($modelcode, $machine_name, $machine_model, $machine_desc) = FakerDataStore::get('machine_factory', 'machine');
// } catch (\Throwable $th) {
list($modelcode, $machine_name, $machine_model, $machine_desc) = ['P7QM', 'MacPro', 'MacPro7,1', 'Mac Pro (2019)'];
// }

$computerName = $faker->firstName() . '\'s ' . $machine_name;
list($os_version, $build) = $this->faker->randomElement($oses);

return [
'serial_number' => $faker->unique()->regexify('[A-Z0-9]{3}[CDFGHJKLMNPQRSTVWXYZ][123456789CDFGHJKLMNPQRTVWXY][A-Z0-9]{3}P7QM'),
'hostname' => $faker->domainWord() . '.local',
'machine_model' => $machine_model,
'machine_desc' => $machine_desc,
'img_url' => '',
'cpu' => $faker->text,
'current_processor_speed' => $faker->randomFloat(2, 1, 4) . " GHz",
'cpu_arch' => 'x86_64',
'os_version' => $os_version,
'physical_memory' => $faker->randomElement([4,8,16,32]),
'platform_uuid' => $faker->uuid,
'number_processors' => $faker->randomElement([2,4,6,8]),
'SMC_version_system' => $faker->randomFloat(2, 1, 3) . 'f' . $faker->randomDigit,
'boot_rom_version' => $faker->regexify('[IMBP]{2}\.[0-9]{4}\.[A-Z]+'),
'bus_speed' => $faker->randomElement([null, '1.07 Ghz']),
'computer_name' => $computerName,
'l2_cache' => $faker->randomElement([null, '3 MB', '6 MB']),
'machine_name' => $machine_name,
'packages' => 1,
'buildversion' => $build,
];
});
$computerName = $this->faker->firstName() . '\'s ' . $machine_name;

return [
'serial_number' => $this->faker->unique()->regexify('[A-Z0-9]{3}[CDFGHJKLMNPQRSTVWXYZ][123456789CDFGHJKLMNPQRTVWXY][A-Z0-9]{3}P7QM'),
'hostname' => $this->faker->domainWord() . '.local',
'machine_model' => $machine_model,
'machine_desc' => $machine_desc,
'img_url' => '',
'cpu' => $this->faker->text,
'current_processor_speed' => $this->faker->randomFloat(2, 1, 4) . " GHz",
'cpu_arch' => 'x86_64',
'os_version' => $os_version,
'physical_memory' => $this->faker->randomElement([4,8,16,32]),
'platform_uuid' => $this->faker->uuid,
'number_processors' => $this->faker->randomElement([2,4,6,8]),
'SMC_version_system' => $this->faker->randomFloat(2, 1, 3) . 'f' . $this->faker->randomDigit,
'boot_rom_version' => $this->faker->regexify('[IMBP]{2}\.[0-9]{4}\.[A-Z]+'),
'bus_speed' => $this->faker->randomElement([null, '1.07 Ghz']),
'computer_name' => $computerName,
'l2_cache' => $this->faker->randomElement([null, '3 MB', '6 MB']),
'machine_name' => $machine_name,
'packages' => 1,
'buildversion' => $build,
];
}
}
34 changes: 17 additions & 17 deletions database/factories/MachineGroupFactory.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
namespace Database\Factories;

/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(App\MachineGroup::class, function (Faker\Generator $faker) {
return [
'name' => $faker->name,
'key' => $faker->uuid,
];
});
use Illuminate\Database\Eloquent\Factories\Factory;

class MachineGroupFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'key' => $this->faker->uuid,
];
}
}
63 changes: 38 additions & 25 deletions database/factories/ReportDataFactory.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(\App\ReportData::class, function (Faker\Generator $faker) {
namespace Database\Factories;

$machines = [
['JYVX', 'Macmini', 'Macmini8,1', 'Mac mini (2018)'],
['HDNK', 'MacBook', 'MacBook9,1', 'MacBook (Retina, 12-inch, Early 2016)'],
['MD6N', 'MacBook Pro', 'MacBookPro16,1', 'MacBook Pro (16-inch, 2019)'],
['H1DP', 'MacBook Pro', 'MacBookPro12,1', 'MacBook Pro (Retina, 13-inch, Early 2015)'],
['J9X6', 'iMac', 'iMac18,3', 'iMac (Retina 5K, 27-inch, 2017)'],
['JWDW', 'iMac', 'iMac19,2', 'iMac (Retina 4K, 21.5-inch, 2019)'],
['P7QM', 'MacPro', 'MacPro7,1', 'Mac Pro (2019)'],
];
use Illuminate\Database\Eloquent\Factories\Factory;

FakerDataStore::add('machine', $faker->randomElement($machines));
list($modelcode, $machine_name, $machine_model, $machine_desc) = FakerDataStore::get('reportdata_factory', 'machine');
class ReportDataFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$machines = [
['JYVX', 'Macmini', 'Macmini8,1', 'Mac mini (2018)'],
['HDNK', 'MacBook', 'MacBook9,1', 'MacBook (Retina, 12-inch, Early 2016)'],
['MD6N', 'MacBook Pro', 'MacBookPro16,1', 'MacBook Pro (16-inch, 2019)'],
['H1DP', 'MacBook Pro', 'MacBookPro12,1', 'MacBook Pro (Retina, 13-inch, Early 2015)'],
['J9X6', 'iMac', 'iMac18,3', 'iMac (Retina 5K, 27-inch, 2017)'],
['JWDW', 'iMac', 'iMac19,2', 'iMac (Retina 4K, 21.5-inch, 2019)'],
['P7QM', 'MacPro', 'MacPro7,1', 'Mac Pro (2019)'],
];

return [
'serial_number' => $faker->unique()->regexify('[A-Z0-9]{3}[CDFGHJKLMNPQRSTVWXYZ][123456789CDFGHJKLMNPQRTVWXY][A-Z0-9]{3}') .$modelcode,
'console_user' => $faker->userName,
'long_username' => $faker->name,
'remote_ip' => $faker->ipv4,
'uptime' => $faker->numberBetween(0, 1000000),
'reg_timestamp' => $faker->dateTimeBetween('-4 years')->format('U'),
'machine_group' => 0,
'archive_status' => $faker->numberBetween(0, 1),
'timestamp' =>$faker->dateTimeBetween('-2 months')->format('U'),
];
});
// FakerDataStore::add('machine', $this->faker->randomElement($machines));
// list($modelcode, $machine_name, $machine_model, $machine_desc) = FakerDataStore::get('reportdata_factory', 'machine');

$machine = $this->faker->randomElement($machines);
list($modelcode, $machine_name, $machine_model, $machine_desc) = $machine;
return [
'serial_number' => $this->faker->unique()->regexify('[A-Z0-9]{3}[CDFGHJKLMNPQRSTVWXYZ][123456789CDFGHJKLMNPQRTVWXY][A-Z0-9]{3}') .$modelcode,
'console_user' => $this->faker->userName,
'long_username' => $this->faker->name,
'remote_ip' => $this->faker->ipv4,
'uptime' => $this->faker->numberBetween(0, 1000000),
'reg_timestamp' => $this->faker->dateTimeBetween('-4 years')->format('U'),
'machine_group' => 0,
'archive_status' => $this->faker->numberBetween(0, 1),
'timestamp' =>$this->faker->dateTimeBetween('-2 months')->format('U'),
];
}
}
27 changes: 17 additions & 10 deletions database/factories/UserContactMethodFactory.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;

use App\UserContactMethod;
use Faker\Generator as Faker;
use Illuminate\Database\Eloquent\Factories\Factory;

$factory->define(
UserContactMethod::class, function (Faker $faker) {
return [
"channel" => "mail",
"address" => $faker->email,
];
});
class UserContactMethodFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
"channel" => "mail",
"address" => $this->faker->email,
];
}
}
Loading

0 comments on commit 5dba346

Please sign in to comment.