如何使用InSpec检查当前用户主目录中的文件和文件夹?

时间:2019-07-30 12:01:11

标签: chef inspec

给出一个厨师食谱,该食谱将在当前用户的主目录中创建文件和文件夹:

[3,1;1,3]

现在,我想编写inspec测试来检查该文件:

import { Injectable } from '@angular/core';
import {
        Router,
        CanActivate,
        ActivatedRouteSnapshot,
        RouterStateSnapshot
} from '@angular/router';
import { SessionService } from './session.service';

@Injectable({
  providedIn: 'root'
})
export class AfterLoginGuard implements CanActivate {
   constructor(private router: Router, private session: SessionService) {}
   canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
   const currentUser = this.session.currentUserValue;
   if (currentUser) {
      // authorized so return true
      return true;
   }

   // not logged in so redirect to login page with the return url
   this.router.navigate(['/admin/login'], {
      queryParams: { returnUrl: state.url }
   });
   return false;
  }
}

这失败。所以我尝试了:

# Installs admin Kubernetes configuration to the user's home folder
execute 'kube config' do
  command <<-CMD
    mkdir -p $HOME/.kube
    cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    chown $(id -u):$(id -g) $HOME/.kube/config
    chmod 0644 $HOME/.kube/config
  CMD
  not_if 'test -f $HOME/.kube/config'
end

但是它也失败了。

我发现可行的唯一方法,但对我来说真的很脆弱:

describe file('$HOME/.kube/config') do
  it { should exist }
end

这假定运行insep的用户将位于所需的文件夹中:/

0 个答案:

没有答案