【问题标题】:Meteor audit-argument-checksMeteor 审计参数检查
【发布时间】:2017-10-16 23:06:48
【问题描述】:

我有一个 Meteor 项目,我正在使用审计参数检查。我收到一条错误消息

Error: Did not check() all arguments during publisher 'document

我知道这与 audit-argument-check 无法检查所有参数有关。但就我而言,我检查了所有这些。具体来说,我已经定义了一个集合“文档”并附加了一个 SimpleSchema。作为 Iron-router 的一部分,我有以下内容:

Router.route('customerDocumentShow', {
    template: 'customerDocumentShow',
    path: 'customer/documents/:_id',
    waitOn: function () {
      return Meteor.subscribe('document', this.params._id);
    },
    data: function () {
      return Documents.findOne(this.params._id);
    }
  });

所以我只传递了 documentId (this.params._id)。在服务器上,我定义了一个方法:

Meteor.methods({
  documentsReadMethod: function(documentId){
    check(documentId, String);

    var documentItem = Document.findOne(argument);

    if (!documentItem) {
      throw new Meteor.Error(500, 'Error 500: Not Found', 'No documents found.');
    }

    return documentItem;
  }
});

所以我在服务器方法中检查 documentId。所以不知道为什么我会收到此错误消息。

注意:我不完全确定的一件事是我需要如何调用此方法(现在是documentsReadMethod_。我没有明确调用(在客户端上):

Meteor.call(documentsReadMethod, this.params_id);

因为我使用的是 autoform、collection2 和 simpleschema。我已经度过了整个周末,但没有任何线索。有什么想法吗?

注意:代码在github上:https://github.com/wymedia/meteor-starter-base

【问题讨论】:

    标签: meteor


    【解决方案1】:

    问题出在发布中。你没有在这里检查 id:

    https://github.com/wymedia/meteor-starter-base/blob/master/server/publications/documents.js#L16

    只需在第 16 行添加 check(id, String); 即可。

    【讨论】:

    • 嗨@acemtp,非常感谢。这确实很完美。不过关于 Meteor.methods 的快速问题。因此,我在客户端以及 Meteor.methods 上都做了允许/拒绝,但我不认为它们会被执行。任何线索为什么?我想进行服务器端验证,最好不必使用允许/拒绝
    • 你混合了两个概念:1/发布/订阅/允许/拒绝:处理数据流和2/方法/调用:远程过程调用系统。只有在客户端执行 Meteor.call('documentsReadMethod', id); 时才会调用您的方法
    • 我明白了。那么结论是使用 Autoform,您只能使用允许/拒绝(因为您没有使用 autoform 显式调用 Meteor.call)?
    • 您可以将meteor.call / 方法与autoform 一起使用,但这不是默认行为。查看他们文档中的示例:github.com/aldeed/meteor-autoform#an-example-contact-form
    【解决方案2】:

    我和另一个tuto也有同样的问题!

    check is not defined in meteor.js 找到答案:从 Meteor v1.2 开始,你必须添加这个包:

    $ meteor add check
    

    【讨论】:

      猜你喜欢
      • 2017-02-23
      • 1970-01-01
      • 2015-01-03
      • 2019-06-19
      • 2017-08-25
      • 1970-01-01
      • 1970-01-01
      • 2013-10-08
      • 2018-02-26
      相关资源
      最近更新 更多